Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
4739 Zobrazení

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
Zrušit
Autor Nejlepší odpověď

¡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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
bře 19
4399
1
pro 22
6181
8
pro 22
5518
3
srp 22
11948
2
pro 19
2969