This question has been flagged
1 Reply
4274 Views

hi, how to replace the product object in the customet.r invoice? i can not inherit from the product.product it show an error!!

ProgrammingError: column product_product.name does not exist LINE 1: SELECT product_product."name",product_product."price",produc...

Avatar
Discard

What do you want do exactly.

Author

i want to replace products in the customer invoices by another object,so i try to inherit from the product,any other solution pleasE?

i have added ans check it

Best Answer

Hi,

Try below code

Add in .py file

class account_invoice_line(osv.osv):
    _inherit = "account.invoice.line"
    _columns = {
            'your_new_field': fields.many2one('your object name', 'Field name',),
            }
account_invoice_line()

Add in .xml file

<record id="invoice_customer_invoice_form" model="ir.ui.view">
    <field name="name">account.invoice.customer.form.test</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="account.invoice_form"/>
    <field name="arch" type="xml">
            <xpath expr="/form/sheet/notebook/page/field[@name='invoice_line']/tree/field[@name='product_id']" position="replace">
                <field name="product_id" on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, context, parent.company_id)" invisible="1"/>
            </xpath>

            <xpath expr="/form/sheet/notebook/page/field[@name='invoice_line']/tree/field[@name='name']" position="before">
                <field name="your_new_field"/>
            </xpath>

    </field>
</record>
Avatar
Discard
Author

thaaaanks for it,but how to modify the fields like(amount,unit price,deciprtion) dynamically from my new object??

Use oncange_method like product oncange_method in account_invoice.py

Author

an example please?how to dynamically change the amount ?

Refer account >> account_invoice.py file in this file there is one method product_id_change this method will help you and also check account_invoice_view.xml line no 51 if you problem is solve than give vote to answer

Author

well done thanks soo much sur :)))

Author

pleaase how can i load the invoice line automaticaaly :when i choose the customer it will load all invoice lines in relation with the chosen customer????