在Odoo 10中继承POS Javascript函数

bi

我正在尝试继承和修改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`

我该如何继承呢?

尝试下面的代码段!已经在测试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文件!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章