Odoo Help

Welcome!

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

0

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

By
Odoo
on 7/1/14, 2:28 AM 1,064 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...........

 

 

 

 

 

 

0

René Schuster

--René Schuster--
1560
| 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:

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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