跳至内容
菜单
此问题已终结
1 回复
7154 查看

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
10月 22
9342
2
11月 19
10353
0
8月 18
2216
2
12月 23
6685
2
12月 23
11746