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

DataError: invalid input syntax for integer: "new_total" shows in my custom onchange method--

By
Odoo
on 6/30/14, 2:43 PM 1,467 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------------

 

 

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 7/1/14, 12:58 AM

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

          

 

 

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

Odoo
on 7/1/14, 2:07 AM

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

Odoo
on 7/1/14, 2:10 AM

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

Prakash
on 7/1/14, 3:55 AM

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

Odoo
on 7/1/14, 5:08 AM

where i can use the browse method in ur above code

Odoo
on 7/1/14, 5:09 AM

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

Prakash
on 7/1/14, 5:12 AM

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

Odoo
on 7/1/14, 5:20 AM

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: 6/30/14, 2:43 PM
Seen: 1467 times
Last updated: 3/16/15, 8:10 AM