在Odoo 10中继承POS Javascript函数

时间:2018-04-18 08:14:40

标签: javascript inheritance odoo odoo-10

我正在尝试继承和修改point_of_sale模块的现有js函数。 这是我需要继承的功能

models.js

exports.Orderline = Backbone.Model.extend({
set_quantity: function(quantity){
    console.log('quantity',quantity);
    this.order.assert_editable();
    if(quantity === 'remove'){
        this.order.remove_orderline(this);
        return;
    }else{
        var quant = parseFloat(quantity) || 0;
        var unit = this.get_unit();
        if(unit){
            if (unit.rounding) {
                this.quantity    = round_pr(quant, unit.rounding);
                var decimals = this.pos.dp['Product Unit of Measure'];
                this.quantityStr = formats.format_value(round_di(this.quantity, decimals), { type: 'float', digits: [69, decimals]});
            } else {
                this.quantity    = round_pr(quant, 1);
                this.quantityStr = this.quantity.toFixed(0);
            }
        }else{
            this.quantity    = quant;
            this.quantityStr = '' + this.quantity;
        }
    }
    this.trigger('change',this);
},
});

这是我的代码:

pos_model.js

odoo.define('point_of_sale.models_inherit', function (require) {
"use strict";

   var module = require('point_of_sale.models');
   module.include({

   set_quantity: function(quantity){
       console.log('initialize');
             }


     }); 

 });

现在我在控制台中收到错误,

 `module.include is not a function`

我怎样才能继承这个?

2 个答案:

答案 0 :(得分:1)

尝试下面的代码片段!!已在Odoo v10.0

中测试过
odoo.define('point_of_sale.models', function (require) {
"use strict";

var models = require('point_of_sale.models');

var _super_orderline = models.Orderline.prototype;

models.Orderline = models.Orderline.extend({
    set_quantity: function(quantity){

        // Call SUPER method!!
        _super_orderline.set_quantity.apply(this,arguments);

        // =============
        // DO YOUR STUFF
        // =============

    }
});

});
顺便说一句,你可以在odoo 10中找到相同的例子...... 检查multiprint.js文件!!

答案 1 :(得分:0)

我认为您需要使用module.Orderline.include代替module.include [source],因为point_of_sale.modelsobject

odoo.define('point_of_sale.models_inherit', function (require) {
    "use strict";

    var module = require('point_of_sale.models');
    module.Orderline.include({
        set_quantity: function(quantity) {
            console.log('initialize');
        }
    });

});