首页 > 解决方案 > Odoo PoS 未在收据中显示自定义字段

问题描述

我在“res.company”模型中添加了一个字段,我正在尝试将它们添加到收据中,但它们没有出现。我已经在下一个 python 文件中添加了这些字段:

# -*- coding: utf-8 -*-

from odoo import models, fields, api, exceptions


class MyModuleCompany(models.Model):
    _inherit = 'res.company'

    branch_code = fields.Integer(string='Branch code')

然后使用以下代码在 POS 公司模型中添加字段:

odoo.define('my_module.company', function (require) {
    "use strict";

    var models = require('point_of_sale.models');

    models.load_fields('res.company', [
        'branch_code'
    ]);

});

最后,我尝试使用下一个 xml 代码使它们出现在收据中:

<?xml version="1.0" encoding="UTF-8"?>
<template xml:space="preserve">

    <t t-extend="OrderReceipt">
        <t t-jquery=".pos-receipt-contact" t-operation="replace">
            <div class="pos-receipt-contact">
                <t t-if='receipt.company.name'>
                    <div><t t-esc='receipt.company.name' /></div>
                </t>
                <t t-if='receipt.company.branch_code'>
                    <div>Branch:<t t-esc='receipt.company.branch_code' /></div>
                </t>
            </div>
        </t>
    </t>

</template>

“名称”字段出现,但由于某种原因“分支”字段没有出现,我无法找出原因。

标签: odoocustomizationposodoo-13

解决方案


它已经在l10n_fr_pos_cert模块中继承。

我可以看到 XML 文件头的差异。他们用:

<templates id="template" xml:space="preserve">

 
编辑:

您已成功将该字段添加到posmodel(pos变量),您只需使该值在收据中可访问。

var models = require('point_of_sale.models');
var _super_ordermodel = models.Order.prototype;

models.Order = models.Order.extend({
    export_for_printing: function(){
        var receipt = _super_ordermodel.export_for_printing.apply(this, arguments);
        receipt.company.branch_code = this.pos.company.branch_code;
        return receipt;
    },
});

推荐阅读