gpt4 book ai didi

javascript - 如何继承pos中的models.js并做一些改动?

转载 作者:行者123 更新时间:2023-12-03 07:11:25 24 4
gpt4 key购买 nike

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: '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 以查看阿拉伯语翻译。然后只有我才能及时提交我的项目,我确实被困住了,请帮助我。我是一名实习生。要在 models.js 中必要的 POS 模块中添加新字段,请覆盖我们从“point_of_sale.models”获取的父模型中的 PosModel。

经过一些改动

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') { throw new Error('Product multi POS needs jQuery'); }

+function ($) {
'use strict';

openerp.your_module_name = function(instance, module) {
var PosModelParent = instance.point_of_sale.PosModel;
instance.point_of_sale.PosModel = instance.point_of_sale.PosModel.extend({
load_server_data: function(){
var self = this;

self.models.forEach(function(elem) {
if (elem.model == 'res.company') {
elem.fields = // make your new assignations here
elem.domain = // ...
elem.loaded = // ...
} else if (elem.model == 'product.product') {
// [...]
}
})

var loaded = PosModelParent.prototype.load_server_data.apply(this, arguments);
return loaded;
},

});
}
}(jQuery);

关于javascript - 如何继承pos中的models.js并做一些改动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48763891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com