تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
7669 أدوات العرض

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


الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب

Thank You..

Did my answer was helpful?

الكاتب

Yes, I got the output..

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
أكتوبر 22
9976
2
نوفمبر 19
10990
0
أغسطس 18
2692
2
ديسمبر 23
7114
2
ديسمبر 23
12738