Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
4701 Vistas

Hi.

This is a very strange behaviour. Let me explain.

I need to add a fied to invoice form. To do that

1) I've created custom module to inherit account.invoice and added the field

2) I've created a view and inherited account.form_view

3) I've inserted the new field in the new view.

Stange behaviour:

If I put the field in the main body (not into a notebook element) of th invoice, all works fine. If I insert the field after invoice's secodary field (in my case this secondary field is "name" inside "Other info" notebook), a "field does not exist" error arises.

My model:

class InvoiceInherit (models.Model):
    _inherit = 'account.invoice'
ref2 = fields.Char(string='Reference2',readonly=True, states={'draft': [('readonly', False)]}, copy=False, help='It will appear in invoice doc under "Client order''s date')

My view ("invoice_form_ref2"):

<?xml version="1.0" encoding="UTF-8"?>
<odoo>

    <record id="view_partner_form_id" model="ir.ui.view">
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <field name="ref" position="after">
                <field name="provider_id"
                       placeholder="Provider ID"/>
            </field>
        </field>
    </record>

    <record id="invoice_form_ref2" model="ir.ui.view">
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_form"/>
        <field name="arch" type="xml">
            <field name="name" position="after"> <-- with this, raise an "field ref2 does not exist" error on update module
                <field name="ref2"/>
            </field>
        </field>
    </record>
</odoo>

if I use

<field name="payment_term_id" position="after">

All things work fine.

Please, note that both fields "name" and "payment_term_id" exists into account.invoce but are rendered in different positions:

"payment_term_id" is redered in the "main" invoice body, but

"name" is rendered inside "other info" notebook.

Thank yu for your help

Avatar
Descartar
Autor Mejor respuesta

¡SOLVED!

It has been my mistake.

In the account.invoice_form view there is another field "name", so the "field name="name" clause appears twice.

The error appears because Odoo does not know which of the two is referenced. I thought it was because of the position, but it was because of the name of the field.

I've used a xpath expression to replace the inside of the group ("other info") where I want to add the new field.


Anyway, thank you Niyas for your help.

Avatar
Descartar
Mejor respuesta

Hi, 

The problem is with the inherit_id , when you refer the field in original view (invoice_form ) , you can use inherit_id as account.invoice_form , that  is why the first case worked fine for you.

Later the field you referring will be coming from an inherited view, check and find that view and use it as the inherit_id .


Thanks


       
Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
mar 19
4344
1
dic 22
6134
8
dic 22
5444
3
ago 22
11911
2
dic 19
2857