Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
7496 Vizualizări

Hi,

I need to create a new column in Purchase order invoice line and Purchase order invoice header. I have inherited the class in both xml and python but it doesn't added.

My Code..

In Python:

                class AccountInvoice(models.Model):

                _inherit = 'account.invoice'

                my_field= fields.Float(string='My Field', readonly=True)


                class AccountInvoiceLine(models.Model):

                """ Override AccountInvoice_line to add the link to the purchase order line

                  it is related to"""

                   _inherit = 'account.invoice.line'


                   _my_field_1= fields.Many2many('example.table', string='My Field 1')


In XML:

            <record id="view_invoice_line_form_inherit" model="ir.ui.view">

                <field name="name">account.invoice.line.form.inherit</field>

                <field name="model">account.invoice</field>

                <field name="inherit_id" ref="account.view_invoice_line_form"/>

                <field name="arch" type="xml">

                        <xpath expr="/form/sheet/notebook/page[1]/field[@name='order_line']/tree//field[@name='discount']"

position="after">

                                    <field name="_my_field_1" widget="many2many_tags"/>

                         </xpath>

                         <xpath expr="/field[@name='amount_tax']"

position="after">

                                    <field name="my_field"/>

                          </xpath>

                    </field>

              </record>


So can anyone tell me how to add a custom fields into the Purchase Order invoice


Imagine profil
Abandonează
Cel mai bun răspuns

Hi Siviaa

You should fix it modifying your views like this

<record id="view_invoice_line_form_inherit" model="ir.ui.view">
                <field name="name">account.invoice.line.form.inherit</field>
                <field name="model">account.invoice</field>
                <field name="inherit_id" ref="account.view_invoice_line_form"/>
                <field name="arch" type="xml">
                        <field name="discount" position="after">
                                    <field name="_my_field_1" widget="many2many_tags"/>
                         </field>
                </field>
</record>

<record id="view_invoice_line_form_inherit" model="ir.ui.view">
                <field name="name">account.invoice.line.form.inherit</field>
                <field name="model">account.invoice</field>
                <field name="inherit_id" ref="account.invoice_supplier_form"/>
                <field name="arch" type="xml">
                        <xpath expr="/form/sheet/notebook/page[1]/field[@name='invoice_line_ids']/tree/field[@name='discount']"
position="after">
                                    <field name="_my_field_1" widget="many2many_tags"/>
                         </xpath>
                         <field name="amount_tax" position="after">
                                    <field name="my_field"/>
                          </field>
                </field>
</record>

The first one is the invoice.line form that doesn't contains account invoice fields, I just keep it just in case you are using it for anything else but I think that the second view inheritance is your desired behavior

See the words in bold for the changes

Imagine profil
Abandonează
Autor

Thank You..

Did my answer was helpful?

Autor

Yes, I got the output..

It's polite the to upvote and accept the answers that help you

Related Posts Răspunsuri Vizualizări Activitate
2
oct. 22
9727
2
nov. 19
10737
0
aug. 18
2528
2
dec. 23
6917
2
dec. 23
12463