Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
7493 Vizualizări

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)])
Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor

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'

Autor

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?

Autor

Great, thanks!

Related Posts Răspunsuri Vizualizări Activitate
0
mar. 21
6457
3
iul. 20
20730
2
ian. 19
6766
1
dec. 18
2833
1
iul. 18
7233