This question has been flagged

In python if I would like to concatenate a string and a number i need just a simple syntax like 

product_id = 1
product = 'product.product,' + str(product_id)
print product

to get as a result

product = product.product,1

In a module for Odoo 10 I have:

@api.depends('price_unit', 'qty')	
def _compute_cst_line(self):
sql_std_cst = 'SELECT value_float FROM ir_property WHERE res_id = %s'
for record in self:
    product = 'product.product,' + str(record.product_id)
     self.env.cr.execute(sql_std_cst,[product])
 ###############more stuff here###############
        _logger.info('product = %s, product)

And as a result I get

product = product.product,product.product(1,)

As a temporary workaround I'm using 're' for extracting the numbers:

import re
self.env.cr.execute(sql_std_cst,['product.product,'
+ str(re.findall(r'\d+', str(record.product_id))[0])])

 But I'm still curious to know what is the correct syntax.

EDIT - Solved with:

self.env.cr.execute(sql_std_cst,['product.product,' + str(record.product_id.id)])
Avatar
Discard
Best Answer

Try this:

str(record.product_id.id)

record.product_id.id  ... it is integer

record.product_id   ... it is the recordset, in your case = product.product(1,)

Avatar
Discard
Author

Got it, thanks.

Then every time I need to pick just the integer I must add a '.id' to the end of the recordset?

YES, must add a 'id'

Author

zbik,

I didn't find adeguate infos reading the link you gave me. Any other useful link about how to correctly use .name or .id?

Author

Great, thanks!