覆盖Odoo 11中的javascript函数?

时间:2018-12-16 09:25:34

标签: odoo odoo-11

我想继承add_product中的函数models.Order

这是原始功能

/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();
    }
},

我需要再添加一个条件,

   if(options.is_promo !== undefined){
    line.set_promo(options.is_promo);
  }

},

所以在我的自定义模块中,我尝试了

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

},

但是会引发错误,line未定义。

我该怎么办?

0 个答案:

没有答案