Odoo Help


Please explain how to write onchange method in 'invoice_line_tax_id' field in account.invoice.line model for a custom Module

on 7/1/14, 2:28 AM 1,605 views


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...........








René Schuster

--René Schuster--
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 7/2/14, 8:33 AM

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:


        <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>


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


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



About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/1/14, 2:28 AM
Seen: 1605 times
Last updated: 3/16/15, 8:10 AM