Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7697 Lượt xem

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


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank You..

Did my answer was helpful?

Tác giả

Yes, I got the output..

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 10 22
9995
2
thg 11 19
11003
0
thg 8 18
2708
2
thg 12 23
7132
2
thg 12 23
12776