Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
6418 Widoki

Hi, i want to add new field on product to show it on pos receipt in odoo v14, any help please

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,
First add the field by inheriting 'product.product' model.

class Product(models.Model):
    _inherit = 'product.product'
    new_field = fields.Char()

Then write Javascript function to add this new field to PoS model.

odoo.define('module_name.NewField', function(require){
    'use strict';
    var models = require('point_of_sale.models');
    var _super_product = models.PosModel.prototype;
    models.PosModel = models.PosModel.extend({
        initialize: function(session, attributes){
            var self = this;
            models.load_fields('product.product', ['new_field']);
            _super_product.initialize.apply(this, arguments);
        }
    });
});
Now we can pass this field to the receipt.

odoo.define('module_name.receipt', function(require){
    "use strict";
    var models = require('point_of_sale.models');
    models.load_fields('product.product', 'product_grade_id');
    var _super_orderline = models.Orderline.prototype;
    models.Orderline = models.Orderline.extend({
        export_for_printing: function(){
            var line = _super_orderline.export_for_printing.apply(this, arguments);
            line.new_field = this.get_product().new_field;
            return line;
        }
    });
});
Now you can inherit the OrderReceipt template to add the new field

https://ibb.co/3Yb3StF

Regards

Awatar
Odrzuć
Autor

Thanks...solved :)

Najlepsza odpowiedź
First add the field by inheriting 'product.product' model.

this code is in which file? 

Then write Javascript function to add this new field to PoS model.

this code is into models.js file?

Sorry but i'm a newby. 

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lis 23
673
1
sie 23
1121
0
maj 23
1702
0
gru 22
1330
0
paź 22
2082