This question has been flagged
1 Reply
4246 Views

Hi,

this is my scenario

I add three fields like a1,a2 and total in  account.invoice.line model use inheritance.Then compute this

sum=a1+a2                                   (This is ok)

But After that i want to know how to add onchange of existing field for  'invoice_line_tax_id

 calculation ####total=sum+invoice_line_tax_id (want to use onchange invoice_line_tax_id ).

Also  I want to know how to write in xml file for this invoice_line_tax_id  when onchange is happend..

Need a help...........

 

 

 

 

 

 

Avatar
Discard
Best Answer

In your custom model that inherits from account.invoice.line, add the on_change method:

def onchange_tax_id(self, cr, uid, ids, tax_id, sum):
    line = self.browse(cr, uid, ids, context=None)[0];
    tax = self.pool.get('account.tax').browse(cr, uid, tax_id, context=None);
    return {'value': {'total': line.sum+tax.amount}};

 

For the view, you need to create a xml file and add it in __openerp__.py:

<openerp>
    <data>

        <record id="your_view_id" model="ir.ui.view">
            <field name="name">your.view.name</field>
            <field name="model">account.invoice.line</field>
            <field name="inherit_id" ref="account.account_invoice_line"></field>
            <field name="arch" type="xml">
                <field name="invoice_line_tax_id" position="attributes">
                    <attribute name="on_change">onchange_tax_id(invoice_line_tax_id, sum)</attribute>
                </field>
            </field>
        </record>

    </data>
</openerp>   

Also make sure that your cusom field 'sum' is in the view.

EDIT:

As an alternative, you could make 'total' a function field.

 

Regards.

Avatar
Discard