我正在尝试将数据添加到 POS 的订单中,并将该数据发送到基于站点https://odoo-development.readthedocs.io/en/latest/dev/pos/load-data的“pos.order”模型-to-pos.html。为了使我的案例更通用,我正在创建一个名为“custom.model”的新 odoo 模型,我正在创建与“pos.config”的关系,以帮助我使用 javascritp 中的模型域,后者使用以下代码:
# -*- coding: utf-8 -*-
from odoo import models, fields
class custom_model(models.Model):
_name = 'custom.model'
name = fields.Char(string='name')
class myPosConfig(models.Model):
_inherit = 'pos.config'
custom_model_id = fields.Many2one('custom.model', string='My custom model')
然后我使用以下 python 代码添加我对“pos.order”模型感兴趣的关系:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class myPosOrder(models.Model):
_inherit = 'pos.order'
custom_model_id = fields.Many2one('custom.model', string='My model')
然后我在前端添加我的自定义模型,其中包含一个带有以下代码的 javascript 文件:
odoo.define('kyohei_pos_computerized_billing.billing_dosage', function (require) {
"use strict";
var models = require('point_of_sale.models');
var _super_order_model = models.Order.prototype;
models.load_models([{
model: 'custom.model',
label: 'custom_model',
fields: ['name'],
// Domain to recover the custom.model record related to my pos.config
domain: function(self){ return [['id', '=', self.config.custom_model_id[0]]];},
loaded: function(self, dosage){self.dosage = dosage[0]},
}]);
});
然后我将以下代码添加到同一个 javascript 文件中,因此记录存储在浏览器中,并在需要时将数据发送到后端:
models.Order = models.Order.extend({
initialize: function(){
_super_order_model.initialize.apply(this,arguments);
if (this.custom_model){
this.custom_model = this.pos.custom_model;
}
},
export_as_JSON: function () {
var data = _super_order_model.export_as_JSON.apply(this, arguments);
data.custom_model = this.custom_model;
return data
},
init_from_JSON: function (json) {
this.custom_model = json.custom_model;
_super_order_model.init_from_JSON.call(this. json);
},
慕丝7291255
潇潇雨雨
相关分类