向Odoo的POS订单添加数据时出错

问题描述 投票:0回答:1

我正在尝试将数据添加到POS的订单,并将该数据发送到基于站点https://odoo-development.readthedocs.io/en/latest/dev/pos/load-data-to-pos.html的“ pos.order”模型。为了使案例更加通用,我正在创建一个名为“ 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);
        },

        export_for_printing: function() {
        var json = _super_order_model.export_for_printing.apply(this,arguments);
        json.custom_model = this.custom_model;
        return json;
        },

    });

最后将以下方法添加到'pos.order'模型,以便它存储前端发送的内容:

    @api.model
    def _process_order(self, order, draft, existing_order):
        pos_order = super(KyoheiComputerizedPosOrder, self)._process_order(order, draft, existing_order)
        if 'custom_model' in order:
            order['custom_model'] = pos_order.custom_model
        return pos_order

但是该字段仍未填充我的custom_model的注册表ID

我正在尝试将数据添加到POS的订单中,并将该数据发送到基于站点https://odoo-development.readthedocs.io/en/latest/dev/pos/load的“ pos.order”模型-data-to-pos.html。让我来说明...

javascript odoo customization pos odoo-13
1个回答
1
投票

此错误归因于方法的参数不匹配,只需在odoo-13上检查此方法_process_order

© www.soinside.com 2019 - 2024. All rights reserved.