콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6451 화면

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

 

 

아바타
취소
베스트 답변

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

작성자

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.

작성자

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

작성자

where i can use the browse method in ur above code

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

작성자

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