如何修改Odoo 8中的Backbone JS函数?
How to modify Backbone JS function in Odoo 8?
我想修改Odoo 8(模块point_of_sale
)中的一段JS代码。原码是这个:
function openerp_pos_models(instance, module){
...
module.Order = Backbone.Model.extend({
...
addPaymentline: function(cashregister) {
var paymentLines = this.get('paymentLines');
var newPaymentline = new module.Paymentline({},{cashregister:cashregister, pos:this.pos});
if(cashregister.journal.type !== 'cash'){
newPaymentline.set_amount( Math.max(this.getDueLeft(),0) );
}
paymentLines.add(newPaymentline);
this.selectPaymentline(newPaymentline);
},
});
}
我修改了该代码的一些行,并且这些更改正在按我想要的方式运行(我只删除了 if (cashregister.journal.type !== 'cash')
行)。问题是现在,我想从我制作的模块中以正确的方式修改这段代码。
为此,我添加了一个 JavaScript 文件,该文件从以下 XML 文件调用(最后一个包含在我的 __openerp__.py
数据中 参数):
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="nmx_pos_ext assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/nmx_pos_ext/static/src/js/nmx_pos_ext.js"></script>
</xpath>
</template>
</data>
</openerp>
而JS文件的内容是:
openerp.nmx_pos_ext = function(instance) {
var _t = instance.web._t;
instance.point_of_sale.Order.include({
addPaymentline: function(cashregister) {
var paymentLines = this.get('paymentLines');
var newPaymentline = new module.Paymentline({},{cashregister:cashregister, pos:this.pos});
newPaymentline.set_amount( Math.max(this.getDueLeft(),0) );
paymentLines.add(newPaymentline);
this.selectPaymentline(newPaymentline);
},
});
}
我更新了模块,但没有应用更改,我收到错误消息,因为 include
似乎不存在于 Backbone 模型中。我尝试使用 set
而不是 include
,但我得到了同样的错误:
instance.point_of_sale.Order.set 不是函数
有人可以帮我吗?
你可以这样试试
openerp.nmx_pos_ext = function(instance) {
var _t = instance.web._t;
var _initialize_Order_ = instance.point_of_sale.Order.prototype;
instance.point_of_sale.Order = instance.point_of_sale.Order.extend({
initialize: function(attributes){
_initialize_Order_.initialize.call(this,attributes);
},
addPaymentline: function(cashregister) {
var paymentLines = this.get('paymentLines');
var newPaymentline = new instance.point_of_sale.Paymentline(
{},
{
cashregister: cashregister,
pos: this.pos
}
);
newPaymentline.set_amount(
Math.max(this.getDueLeft(), 0)
);
paymentLines.add(newPaymentline);
this.selectPaymentline(newPaymentline);
},
});
}
试试这个:
instance.module.Order.include({
addPaymentline: function(cashregister) {
var paymentLines = this.get('paymentLines');
var newPaymentline = new module.Paymentline({},{cashregister:cashregister, pos:this.pos});
newPaymentline.set_amount( Math.max(this.getDueLeft(),0) );
paymentLines.add(newPaymentline);
this.selectPaymentline(newPaymentline);
},
});
我想修改Odoo 8(模块point_of_sale
)中的一段JS代码。原码是这个:
function openerp_pos_models(instance, module){
...
module.Order = Backbone.Model.extend({
...
addPaymentline: function(cashregister) {
var paymentLines = this.get('paymentLines');
var newPaymentline = new module.Paymentline({},{cashregister:cashregister, pos:this.pos});
if(cashregister.journal.type !== 'cash'){
newPaymentline.set_amount( Math.max(this.getDueLeft(),0) );
}
paymentLines.add(newPaymentline);
this.selectPaymentline(newPaymentline);
},
});
}
我修改了该代码的一些行,并且这些更改正在按我想要的方式运行(我只删除了 if (cashregister.journal.type !== 'cash')
行)。问题是现在,我想从我制作的模块中以正确的方式修改这段代码。
为此,我添加了一个 JavaScript 文件,该文件从以下 XML 文件调用(最后一个包含在我的 __openerp__.py
数据中 参数):
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="nmx_pos_ext assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/nmx_pos_ext/static/src/js/nmx_pos_ext.js"></script>
</xpath>
</template>
</data>
</openerp>
而JS文件的内容是:
openerp.nmx_pos_ext = function(instance) {
var _t = instance.web._t;
instance.point_of_sale.Order.include({
addPaymentline: function(cashregister) {
var paymentLines = this.get('paymentLines');
var newPaymentline = new module.Paymentline({},{cashregister:cashregister, pos:this.pos});
newPaymentline.set_amount( Math.max(this.getDueLeft(),0) );
paymentLines.add(newPaymentline);
this.selectPaymentline(newPaymentline);
},
});
}
我更新了模块,但没有应用更改,我收到错误消息,因为 include
似乎不存在于 Backbone 模型中。我尝试使用 set
而不是 include
,但我得到了同样的错误:
instance.point_of_sale.Order.set 不是函数
有人可以帮我吗?
你可以这样试试
openerp.nmx_pos_ext = function(instance) {
var _t = instance.web._t;
var _initialize_Order_ = instance.point_of_sale.Order.prototype;
instance.point_of_sale.Order = instance.point_of_sale.Order.extend({
initialize: function(attributes){
_initialize_Order_.initialize.call(this,attributes);
},
addPaymentline: function(cashregister) {
var paymentLines = this.get('paymentLines');
var newPaymentline = new instance.point_of_sale.Paymentline(
{},
{
cashregister: cashregister,
pos: this.pos
}
);
newPaymentline.set_amount(
Math.max(this.getDueLeft(), 0)
);
paymentLines.add(newPaymentline);
this.selectPaymentline(newPaymentline);
},
});
}
试试这个:
instance.module.Order.include({
addPaymentline: function(cashregister) {
var paymentLines = this.get('paymentLines');
var newPaymentline = new module.Paymentline({},{cashregister:cashregister, pos:this.pos});
newPaymentline.set_amount( Math.max(this.getDueLeft(),0) );
paymentLines.add(newPaymentline);
this.selectPaymentline(newPaymentline);
},
});