1

I added a new field in res.partner , then in customer view of POS ; but when editing or creating a customer ; I got error when saving . Here is my code , what's missing to save field from xml to database? Thanks.

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>
K.ju
  • 541
  • 5
  • 20

1 Answers1

1

Odoo will fail to write the value without the field name, You can see the following error in the log:

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

You need to set the name of the input to my_field.

Example:

<input class='detail client' name="my_field" type="date" t-att-value='partner.my_field'></input>
Kenly
  • 24,317
  • 7
  • 44
  • 60
  • I added the the custom field 'my_field' in backend , I got the correct values displayed in pos; but the error is showing only when create new customer and save it. – Ing Jan 22 '21 at 16:04
  • I should set value from js file? – Ing Jan 22 '21 at 16:07
  • The error is shown when you try to save. Check my edit. – Kenly Jan 22 '21 at 16:30