我想向POS Receipt添加新字段。我想通过继承自定义模块中的js文件来实现。我不知道js所以我不知道如何继承它。在odoo的文件中point of sale > static > src > js > pos.js
model: 'res.company',
fields: [ 'currency_id', 'email', 'website', 'company_registry', 'vat', 'name', 'phone', 'partner_id' , 'country_id', 'tax_calculation_rounding_method'],
ids: function(self){ return [self.user.company_id[0]]; },
loaded: function(self,companies){ self.company = companies[0]; },
我编辑了字段,并添加了我的必填字段说street2
,它来了Pos Receipt
我尝试继承js文件,但它无法正常工作。这是我的代码
var _super = module.PosModel.prototype;
module.PosModel = module.PosModel.extend({
initialize: function (session, attributes) {
_super.initialize.apply(this, arguments);
this.models.push({
model: 'res.company',
fields: ['street2'],
})
return this;
},
});
我还创建了一个xml文件来显示js文件的路径。
XML
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/xn_pos_vat_enhancement_v11/static/src/js/pos_receipt_fields.js"></script>
</xpath>
</template>
</data>
</odoo>
PS:我是js的新手先谢谢你
Odoo版本:11(社区)
我这样做是通过:
odoo.define('xn_pos_vat_enhancement_v11.pos_receipt_fields', function (require) {
var models = require('point_of_sale.models');
var core = require('web.core');
var _t = core._t;
var session = require('web.session');
var rpc = require('web.rpc');
var _super_PosModel = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
get_model: function (_name) {
var _index = this.models.map(function (e) {
return e.model;
}).indexOf(_name);
if (_index > -1) {
return this.models[_index];
}
return false;
},
initialize: function (session, attributes) {
var self = this;
var company_model = this.get_model('res.company');
company_model.fields.push('street','street2','state_id');
_super_PosModel.initialize.apply(this, arguments);
},
get_config: function () {
return this.config;
},
});
});
其中xn_pos_vat_enhancement_v11
是我的模块名称,pos_receipt_fields
是我的文件名。我不知道解释整个代码,如果有人可以接受他们的答案。提前致谢。