Skip to Content
Menu
This question has been flagged
3 Replies
7947 Views

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?

Avatar
Discard
Best Answer

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);

    },

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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);
}

},
});
Avatar
Discard
Related Posts Replies Views Activity
0
Aug 23
194
1
Nov 22
1747
2
Aug 22
5992
1
Feb 22
1731
1
Nov 21
7415