Ajuda

2

odoo8: How to get tax name in python?

Avatar
JC

How to change the code to display tax name/description instead of taxes_id?

 

class product_barcode_print(report_sxw.rml_parse):
    def _getLabelRows(self, form):
        product_obj = self.pool.get('product.product')
data = []
result = {}
product_ids = form['product_ids']

        if not product_ids:
            return {}

        products_data = product_obj.read(self.cr, self.uid, product_ids, ['name','default_code','list_price',
'taxes_id','ean13'])
for product in products_data:
           for product_row in range(int(math.ceil(float(form['qty'])/1))):
                label_row=[]
for row in [1,2,3]:
                    label_data = {
'name': product['name'],,
'default_code': product['default_code'],
'price': product['list_price'],
'igst': product['taxes_id'], }
                    label_row.append(label_data)
data.append(label_row)
        if data:
            return data
else:
            return {}    
 
Avatar
Descartar
5 Respostas
3
Avatar
Janeesh
Best Answer

Try this:

tax_name = ",".join([tax.name for tax in product.taxes_id])
label_data = {                        
 'name': product.name,                        
 'default_code': product.default_code,                        
 'price': product.list_price,                        
 'igst': tax_name
 }
Avatar
Descartar
1
Avatar
Ameera PP
Best Answer

Hi,

Try this way!!!

Just browse the tax record and get the value of field name..


for row in [1,2,3]:
         label_data = {        

                tax_name = self.pool.get('account.tax').browse(self.cr, self.uid, product['taxes_id']).name                                    

               'name': product['name'],,                           

               'default_code': product['default_code'],             

              'price': product['list_price'],            

              'igst': tax_name,      

              }          

       


2 Comentários
Avatar
Descartar
Avatar
Akhil P Sivan
-

Hi, I think this will give error if you have multiple taxes in taxes_id field

Avatar
Ameera PP
-

You need to use a for loop for that

1
Avatar
John Doe
Best Answer


tax_name = ",".join([tax.name for tax in product.taxes_id])
label_data = {                        
 'name': product.name,                        
 'default_code': product.default_code,                        
 'price': product.list_price,                        
 'igst': tax_name
 }


Avatar
Descartar
1
Avatar
Bharat Parmar (bhp)
Best Answer

try with search().

label_data = {

     'name': product['name'],

    'default_code': product['default_code'],

    'price': product['list_price'],

    'igst': self.env['account.tax'].search( [ ('id', '=', product['taxes_id'] ) ] ).name,

}

Avatar
Descartar
0
Avatar
Akhil P Sivan
Best Answer

Hi, 

You may try like this way:

class product_barcode_print(report_sxw.rml_parse):
    def _getLabelRows(self, form):
        product_obj = self.pool.get('product.product')        
        data = []        
        result = {}        
        product_ids = form['product_ids']

        if not product_ids:
            return {}

        products_data = product_obj.browse(self.cr, self.uid, product_ids)        
        for product in products_data:
           for product_row in range(int(math.ceil(float(form['qty'])/1))):
                label_row=[]  
                tax_name = ""
                if product.taxes_id:
                    for t in product.taxes_id:
                        tax_name = str(t.name)+ " "
                for row in [1,2,3]: label_data = { 'name': product.name, 'default_code': product.default_code, 'price': product.list_price, 'igst': tax_name, } label_row.append(label_data) data.append(label_row) if data: return data else: return {}

 

Avatar
Descartar