This question has been flagged
1 Reply
5765 Views

My task is when onchangeof invoice_line_tax_id from customer invoice line then it result should be

result=new_total+invoice_line_tax_id ,But i cannt get the result when the onchange of invoice_line_tax_id is changes.How to resolve this issue.Please need a help

This is the onchange method 

#def onchange_tax_id(self,cr,uid,ids,invoice_line_tax_id,context=None):

 

 

 

from osv import osv,fields


class account_new(osv.osv):
    
    _inherit='account.invoice.line'

    def onchange_schemid(self,cr,uid,ids,price_unit,quantity,context=None):
            if price_unit:
                amount_new=price_unit*quantity
                return {'value':{'new_total':amount_new}}
            return {}
        
    def onchange_tax_id(self,cr,uid,ids,invoice_line_tax_id,context=None):
        a=self.pool.get('account.invoice.line').read(cr,uid,['new_total'],context=context)
        b=self.pool.get('account.tax').read(cr,uid,['invoice_line_tax_id'],context=context)
        if invoice_line_tax_id:
                val1=a[0]['new_total']
                val2=b[0]['invoice_line_tax_id']
                amount_with_tax=val1+val2
                return {'value':{'new_with_tax':amount_with_tax}}
        return {}
        
    _columns={
              'new_total': fields.integer('Gross Amount', required=True),
              'new_with_tax':fields.float('Amount')
              }
    
    
account_new()

 

EDIT------------

.xml  file

<xpath expr="/form/sheet/notebook/page[1]/field[1]/tree/field[11]" position="inside">
                        <field name="invoice_line_tax_id" on_change="onchange_tax_id(invoice_line_tax_id)"/>
                    </xpath>

.py file

 

class account_new(osv.osv):
    
    _inherit='account.invoice.line'

    def onchange_schemid(self,cr,uid,ids,price_unit,quantity,context=None):
            if price_unit:
                amount_new=price_unit*quantity
                return {'value':{'new_total':amount_new}}
            return {}
        
    def onchange_tax_id(self,cr,uid,ids,invoice_line_tax_id,context=None):
        
         acc_tax_obj = self.pool.get('account.tax')
         line_tax = invoice_line_tax_id
         for val in acc_tax_obj.browse(cr, uid, line_tax);
             amount = val.amount
             return {'value':{'new_with_tax':amount}}

But this onchange is not working------------

 

 

Avatar
Discard
Best Answer

invoice_line_tax_id is many2many field it your coding adding total value and many2many field value so its shows error. using many2many value id browse the record needed value and add the total.

Edit

use the browse method example:-

       acc_tax_obj = self.pool.get('account.tax')
       line_tax = invoice_line_tax_id
       for val in acct_tax_obj.browse(cr, uid, line_tax):
          amount = val.amount

          

 

 

Avatar
Discard
Author

Hi Prakash, I want to compute the total based on onchange of 'invoice_line_tax_id' ,so can u tell how to modify this code..

Author

Also please tell how to write onchange of existing field of invoice_line_tax_id in xml file

In xml field inherit using replace tag change the original filed.

Author

Above code is not working i change inside the onchange method but no use

Author

where i can use the browse method in ur above code

I updated code not sure need to debug yourself using print statement.

Author

Is this the correct code??????? def onchange_tax_id(self,cr,uid,ids,invoice_line_tax_id,context=None): sum=0 a=self.read(cr,uid,ids,['new_total'],context) acc_tax_obj = self.pool.get('account.tax').browse(cr,uid,ids) line_tax = invoice_line_tax_id for val in line_tax: amount = acc_tax_obj.invoice_line_tax_id+a['new_total'] print "@@@@@@@@@@@@@@@@@@@@@@",amount return {'value':{'new_with_tax':amount}} return {}