Javascript 如何在pos中继承models.js并进行一些更改?
models_extend.jsJavascript 如何在pos中继承models.js并进行一些更改?,javascript,inheritance,odoo,odoo-10,point-of-sale,Javascript,Inheritance,Odoo,Odoo 10,Point Of Sale,models_extend.js odoo.define('pos_ticket.models_extend', function (require) { "use strict"; var x = require('point_of_sale.models'); var models = pos_model.PosModel.prototype.models; models.push( { model:
odoo.define('pos_ticket.models_extend', function (require) {
"use strict";
var x = require('point_of_sale.models');
var models = pos_model.PosModel.prototype.models;
models.push(
{
model: 'res.company',
fields: [ 'currency_id', 'email', 'website', 'company_registry', 'vat', 'name', 'phone', 'partner_id' , 'country_id', 'tax_calculation_rounding_method','city','trn_no'],
ids: function(self){ return [self.user.company_id[0]]; },
loaded: function(self,companies){ self.company = companies[0]; },
},
{
model: 'product.product',
fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code',
'to_weight', 'uom_id', 'description_sale', 'description',
'product_tmpl_id','tracking','arb'],
order: ['sequence','default_code','name'],
domain: [['sale_ok','=',true],['available_in_pos','=',true]],
context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },
loaded: function(self, products){
self.db.add_products(products);
},
},
{
model: 'product.product',
fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code',
'to_weight', 'uom_id', 'description_sale', 'description',
'product_tmpl_id','tracking','arb'],
order: ['sequence','default_code','name'],
domain: [['sale_ok','=',true],['available_in_pos','=',true]],
context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },
loaded: function(self, products){
self.db.add_products(products);
},
}
);
x.Order = x.Order.extend({
export_for_printing: function(){
var self = this;
this.pos = options.pos;
var company = this.pos.company;
var receipt = {
company:{
city:company.city,
trn_no:company.trn_no,
}
}
return receipt;
},
});
我想在res.company中添加city和trn_no,在product.product中添加arb以查看阿拉伯语翻译。这样只有我才能及时提交我的项目,我真的被困了,请帮助我。我是一名实习生。
要在POS模块中添加新字段,models.js中需要覆盖父模型中的PosModel,我们从“point\u of_sale.models”中获取
经过一些改变
odoo.define('pos_ticket.models_extend', function (require) {
"use strict";
var x = require('point_of_sale.models');
var _super = x.PosModel.prototype;
module.PosModel = x.PosModel.extend({
initialize: function (session, attributes) {
// call super to set all properties
_super.initialize.apply(this, arguments);
// here i can access the models list like this and add an element.
this.models.push(
{
// load allowed users
model: 'res.company',
fields: ['city','trn_no'],
domain: function(self){ return [['id','in',self.users.company_id]]; },
loaded: function(self,companies){
console.log(companies);
self.allowed_users = companies;
}
},{
model: 'product.product',
fields: ['arb'],
order: ['sequence','default_code','name'],
domain: [['sale_ok','=',true],['available_in_pos','=',true]],
context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },
loaded: function(self, products){
self.db.add_products(products);
}
},
)
return this;
}
});
});
现在我需要继承另一个名为“export_for_printing”的函数,并在其中添加这些新字段,以便可以打印这些字段。如何打印?只需像这样将修改添加到
self.models
数组中即可。这适用于版本8。也许你需要适应它:
if(typeof jQuery=='undefined'){抛出新错误('Product multi-POS需要jQuery');}
+函数($){
"严格使用",;
openerp.your_module_name=函数(实例,模块){
var posmodelpent=instance.point\u of_sale.PosModel;
instance.point\u of_sale.PosModel=instance.point\u of_sale.PosModel.extend({
加载服务器数据:函数(){
var self=这个;
self.models.forEach(函数(elem){
如果(elem.model=='res.company'){
elem.fields=//在此处进行新分配
elem.domain=/。。。
加载的元素=/。。。
}else if(elem.model=='product.product'){
// [...]
}
})
var loaded=PosModelParent.prototype.load\u server\u data.apply(这是参数);
返回装载;
},
});
}
}(jQuery);
请有人帮我看看我的答案,我想你和我的问题是一样的:你的疑问解决了吗?没有。仍然无法解决。我想在模型中添加这些字段,以便我可以在pos收据中打印这些字段。当我只是在基础中做一些更改时,它就可以工作了,但我想通过继承js来完成。