Skip to Content
Menu
This question has been flagged
3 Replies
2377 Views

Hello all, I'm using OdooRpc to pull some data from the products template.
Expected behavior: I used to be able to do this...

def pricelist():
odoo = get_session()
p = odoo.env['product.template']

product_ids = p.search([('sale_ok', '=', True)], limit=10, offset=2)
products = p.browse(product_ids)

csv = ""
for p in products:
csv += str(p.categ_id.name) + "," + str(p.name) + "," + str(p.list_price) + "," + str(p.default_code) + "," + str(p.item_ids.fixed_price) + "," + str(p.qty_available) + "\n"

f = open("pricelist-auto.txt", "w")
f.write(csv)

This has stopped working. I'm using Odoo 11 Enterprise.
This is the error I get odoorpc.error.RPCError: Expected singleton: product.template(132,...)

Next attempt: This is terribly inefficient but it worked a couple times...

def pricelist_2():


odoo = get_session()
p = odoo.env['product.template']

product_ids = p.search([('sale_ok', '=', True)])

csv = ""
for pro in product_ids:
p = odoo.env['product.template'].browse(pro)
csv += str(p.categ_id.name) + "," + str(p.name) + "," + str(p.list_price) + "," + str(p.default_code) + "," + str(p.item_ids.fixed_price) + "," + str(p.qty_available) + "\n"

f = open("pricelist-auto.txt", "w")
f.write(csv)

This take 20 minutes because there are like 2000 products. It still come up with the same error.
Mind you the first piece of code was working perfectly fine.

If there I fix for this or am I doing something wrong?

Thanks for any help you can provide.



Avatar
Discard
Best Answer

Hi Fred,

I believe you made a mistake on this


csv += str(p.categ_id.name) + "," + str(p.name) + "," + str(p.list_price) + "," + str(p.default_code) + "," + str(p.item_ids.fixed_price) + "," + str(p.qty_available) + "\n"
item_ids in product.template is a one2many field.
product_ids is already a recordsets you can eliminate the first line of code in the loop


Avatar
Discard
Best Answer

product_ids in both cases is already a set of records, the browsing operation is redundant and you can delete it.

Additionaly browse takes a database id or a list of ids and returns a recordset.

Like: self.browse([7, 18, 12])

in the first case you should use
p.browse(product_ids.ids)

in second
browse(pro.id)

Avatar
Discard
Best Answer
str(p.item_ids.fixed_price): item_ids value may have more than one. 
Do you think that product.product fixed_price are always same? 
If yes, you can use p.item_ids[0].fixed_price .

1 product.template have one or more than one product.product.

You should better to take data from product.product behalf of product.template .




Avatar
Discard