odoo - 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>
“名称”字段出现,但由于某种原因“分支”字段没有出现,我无法找出原因。
解决方案
它已经在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;
},
});
推荐阅读
- git - 我可以使用自己的存储库打开拉取请求并使用自己的提交日志吗?
- html - 将边框应用于 div 可防止其分页
- html - bootstrap4 在移动设备上没有响应(不是视口问题)
- laravel - 检查是否存在上传的文件,显示按钮以查看和下载文件
- python - 如何在物联网设备上安装 gRPC python 包?
- css - Material UI Modal - 渲染上的默认黑色边框在检查时消失
- php - 将 stdClass 转换为数组的问题
- asp.net-mvc - System.ArgumentNullException: '值不能为空。(参数'connectionString')'
- python - 如何在 python 中使用 complexaudio 暂停/恢复播放?
- r - 有没有办法标记由 lda() 生成的每个集群