Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
7480 Представления

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)])
Аватар
Отменить
Лучший ответ

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

Аватар
Отменить
Автор

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'

Автор

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?

Автор

Great, thanks!

Related Posts Ответы Просмотры Активность
0
мар. 21
6437
3
июл. 20
20711
2
янв. 19
6747
1
дек. 18
2822
1
июл. 18
7212