【问题标题】:Invalid field " on model 'res.partner' in POS (Odoo 13)POS(Odoo 13)中模型'res.partner'上的无效字段“
【发布时间】:2021-04-26 22:41:06
【问题描述】:

我在 res.partner 中添加了一个新字段,然后在 POS 的客户视图中;但是在编辑或创建客户时;保存时出错。 这是我的代码,将字段从 xml 保存到数据库缺少什么? 谢谢。

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

var models = require('point_of_sale.models');
models.load_fields('res.partner', ['my_field']);


<templates id="point_of_sale.template" xml:space="preserve">
    <t t-extend="ClientDetails">
        <t t-jquery=".client-details-right" t-operation="append">
            <div class="client-detail">
                <span class="label">My Field</span>
                <t t-if='partner.my_field'>
                     <span class='detail client'><t t-esc='partner.my_field' /></span>
                </t>
                        <t t-if='!partner.my_field'>
                            <span class='detail client empty'>N/A</span>
                 </t>
            </div>

        </t>
    </t>


    <t t-extend="ClientDetailsEdit">
        <t t-jquery=".client-details-right" t-operation="append">
            <div class="client-detail">
                <span class="label">My Field</span>
                       <input class='detail client' type="date" t-att-value='partner.my_field'></input>
            </div>
            </t>
    </t>

</templates>

【问题讨论】:

    标签: javascript python xml odoo pos


    【解决方案1】:

    Odoo会写入不带字段名的值失败,在日志中可以看到如下错误:

    File "C:\Program Files (x86)\Odoo 13.0\server\odoo\models.py", line 3395, in write
        field = self._fields[fname]
    KeyError: ''
    

    您需要将输入的名称设置为my_field

    示例:

    <input class='detail client' name="my_field" type="date" t-att-value='partner.my_field'></input>
    

    【讨论】:

    • 我在后端添加了自定义字段'my_field',我在pos中显示了正确的值;但只有在创建新客户并保存时才会显示错误。
    • 我应该从 js 文件中设置值吗?
    • 尝试保存时显示错误。检查我的编辑。
    猜你喜欢
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多