问题描述
我在 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>
解决方法
如果没有字段名,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>