Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
9100 Lượt xem

I want to inherit function `add_product` of `models.Order`.

Here is the original function

**/point_of_sale/static/src/js/models.js*  

      add_product: function(product, options){

        if(this._printed){

            this.destroy();

            return this.pos.get_order().add_product(product, options);

        }

        this.assert_editable();

        options = options || {};

        var attr = JSON.parse(JSON.stringify(product));

        attr.pos = this.pos;

        attr.order = this;

        var line = new exports.Orderline({}, {pos: this.pos, order: this, product: product});

        if(options.quantity !== undefined){

            line.set_quantity(options.quantity);

        }

        if(options.price !== undefined){

            line.set_unit_price(options.price);

        }


        //To substract from the unit price the included taxes mapped by the fiscal position

        this.fix_tax_included_price(line);

        if(options.discount !== undefined){

            line.set_discount(options.discount);

        }

        if(options.extras !== undefined){

            for (var prop in options.extras) {

                line[prop] = options.extras[prop];

            }

        }

        var to_merge_orderline;

        for (var i = 0; i < this.orderlines.length; i++) {

            if(this.orderlines.at(i).can_be_merged_with(line) && options.merge !== false){

                to_merge_orderline = this.orderlines.at(i);

            }

        }

        if (to_merge_orderline){

            to_merge_orderline.merge(line);

        } else {

            this.orderlines.add(line);

        }

        this.select_orderline(this.get_last_orderline());

        if(line.has_product_lot){

            this.display_lot_popup();

        }

    },


I need to add one more condidtion like,

       if(options.is_promo !== undefined){

        line.set_promo(options.is_promo);

      }

    },


So in my custom module, I tried this,

      

      var _super_order = models.Order.prototype;

      models.Order = models.Order.extend({

    add_product: function(product, options){

      if(options.is_promo !== undefined){

        line.set_promo(options.is_promo);

      }

       _super_order.add_product.apply(this,arguments);

    },


But it throws an error, `line` is not defined.

And I tried to copy the original code into the custom module and made necessary changes. Then run it, gives me an error. exports is not defined 

How can i do it?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

var _super_order = models.Order.prototype;

      models.Order = models.Order.extend({

    add_product: function(product, options){

var line = new exports.Orderline({}, {pos: this.pos, order: this, product: product});

if(options.is_promo !== undefined){

        line.set_promo(options.is_promo);

      }

       _super_order.add_product.apply(this,arguments);

    },

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

have you got any solution for this? I'm also facing the same issue on Odoo15

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

i have trouble with pos odoo 12, i wan inherit function add_product ..but every compile in pos ..i always hava trouble  exports is not defined  ...how i can solve this code 

var _super_order_product_add = models.Order.prototype;
models.Order = models.Order.extend({
initialize: function() {
_super_order.initialize.apply(this,arguments);
},

add_product: function(product, options){

this.assert_editable();
options = options || {};
var attr = JSON.parse(JSON.stringify(product));
console.log(attr);
attr.pos = this.pos;
attr.order = this;
var line = new exports.Orderline({}, {pos: this.pos, order: this, product: product});
console.log(line);

if(options.dikirim !== "0"){
line.set_dikirm(options.dikirim);
}

if(options.dikirim == "0"){
line.set_dikirm(options.dikirim);
}

if(options.diambil !== "0"){
line.set_diambil(options.diambil);
}

if(options.diambil == "0"){
line.set_diambil(options.diambil);
}

if(options.price !== undefined){
line.set_unit_price(options.price);
}

},
});
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 23
194
1
thg 11 22
3221
2
thg 8 22
7569
1
thg 2 22
2827
1
thg 1 25
9232