为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 POS models.js 中扩展初始化函数

如何在 POS models.js 中扩展初始化函数

暮色呼如 2022-07-08 17:07:37
我想在初始化函数中添加变量,但我不知道如何正确执行这是我现在尝试过的odoo.define('tw_pos_inherit_model.attemptInherit', function (require) {    "use strict";    var POSInheritmodel = require('point_of_sale.models');    var _super_order = POSInheritmodel.Order.prototype;    POSInheritmodel.Order = POSInheritmodel.Order.extend({        initialize: function(session,attributes){            var self = this;            this.additional_discount = 0;            _super_order.initialize.apply(this,arguments);        },我试过做这里所说的,但这个例子是针对 PosModel 而不是 Order这是错误point_of_sale.assets.js:79 Cannot read property 'name' of undefined TypeError: Cannot read property 'name' of undefined    at Engine.eval (eval at _render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3416:73), <anonymous>:50:34)    at Engine._render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3415:296)    at Engine.render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3415:151)    at Engine._render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3419:57)    at Engine.render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3415:151)    at Class.render_orderline (http://localhost:8071/web/content/723-a89f195/point_of_sale.assets.js:306:5014)    at Class.renderElement (http://localhost:8071/web/content/723-a89f195/point_of_sale.assets.js:308:354)    at Class.replace (http://localhost:8071/web/content/723-a89f195/point_of_sale.assets.js:307:423)    at Class.start (http://localhost:8071/web/content/723-a89f195/point_of_sale.assets.js:325:810)    at http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3684:52
查看完整描述

1 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

您不需要var self = this;,因为以后不使用它。

此外,您很可能需要从初始化函数返回一些内容。

_super_order.initialize.apply(this,arguments);

应该:

return _super_order.initialize.apply(this,arguments);


查看完整回答
反对 回复 2022-07-08
  • 1 回答
  • 0 关注
  • 99 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号