Closed swscomputers closed 5 years ago
Hi @swscomputers Can you provide the full traceback of the script? (it will help to show which code line generates the error) Did you upgrade OdooRPC or the Odoo server before the error occurs?
EDIT: if you have access to the log of the server it also will help (especially the traceback generated server-side)
It seems to me issue on following line
str(p.item_ids.fixed_price)
In p.item_ids
will have more than one recordset.
str(p.item_ids[0].fixed_price)
will take first fixed_price and ignore other lines. ORp.item_ids
and add on csv file. (which may give you multiple line for same product)Thank you guys I will get the traceback from the server. I will also try bodedra solution to see if that might help.
This has nothing to do with odoorpc, so closing.
Here is the traceback I get from the terminal. This is using the first script with bodedra's suggestion.
Traceback (most recent call last):
File "./all_product_prices.py", line 130, in
what do you mean it has nothing do to with it? It was working before? with Odoo 11.
No, it was working by accident, but the problem is you are accessing a data for multiple records. This is something of Odoo itself, and not an issue, but a misuse of the ORM. The same will happen with direct Odoo code.
Listen I'm prone to make mistakes. I don't doubt I have an error somewhere. But please don't assume I'm ignorant either.
def get_report_values(self, docids, data=None):
lines_per_page = 25 if data['form']['lines_per_page'] == 0 else data['form']['lines_per_page']
products = self.env['product.template'].search([('categ_id.nrg_pricelist', '=', True), '!', ('nrg_pricelist','=', True)], order='categ_id asc, list_price asc')
index = 0
per_side_number = lines_per_page
total_num_in_pages = lines_per_page * 2
leftBool = True
left = []
right = []
pages = []
for product in products:
if(leftBool):
left.append({
'name': product.name,
'categ_name': product.categ_id.name,
'list_price': product.list_price,
'default_code': product.default_code,
})
else:
right.append({
'name': product.name,
'categ_name': product.categ_id.name,
'list_price': product.list_price,
'default_code': product.default_code,
})
if( (index + 1) % total_num_in_pages == 0):
pages.append({
'left': list(left),
'right': list(right)
})
left[:] = []
right[:] = []
if (index + 1 == len(products)):
pages.append({
'left': list(left),
'right': list(right)
})
left[:] = []
right[:] = []
if ( (index + 1) % per_side_number == 0):
leftBool = not leftBool
index = index + 1
return {
'docs': products,
'pages': pages,
}
This is from Odoo itself and it works perfectly fine. I have similar code in multiple places. Again maybe your not wrong. But it's not like It's "misuse the ORM". You come off as real high and mighty.
Anyways thanks all for the help. Off to stackoverflow perhaps.
I'm not assuming you are ignorant, but we should concentrate on real OdooRPC problems here in the issue tracker.
Issue is not with OdooRPC. I am agree with @pedrobaeza
Issue on these line:
File "./all_product_prices.py", line 91, in pricelist
products = p.browse(product_ids)
It seems you have already get browse recordset in product_ids
variable.
products = p.browse(product_ids)
for p in products:
to for p in product_ids:
If you found real problem with OdooRPC, you are most welcome to report it.
IMO You may get help from Odoo forums.
Thanks for the help. That didn't work. Ill check the Odoo forums.
@swscomputers this error seems to happen when OdooRPC try to read
all your product_ids
, this SingletonError can raise because of a (for instance) a compute
field which doesn't loop on self
(this kind of error may stay silent for a long time because it's working well when the field is displayed on a form, but will raise an error if you put it on a tree view (like here where OdooRPC try to read ALL the fields for multiple products, so it could be any code related to them, especially computed field).
EDIT: this call should raise the same error if I'm not wrong:
odoo.env['product.template'].read(product_ids, [])
I know this is an old thread... But I just want to confirm @sebalix is right. The problem is due to the RPC/ORM trying to read all the fields in the record. If you specify the not calculated fields you should have no error. It just happened to me on the pos_order table and this was the answer.
@swscomputers this error seems to happen when OdooRPC try to
read
all yourproduct_ids
, this SingletonError can raise because of a (for instance) acompute
field which doesn't loop onself
(this kind of error may stay silent for a long time because it's working well when the field is displayed on a form, but will raise an error if you put it on a tree view (like here where OdooRPC try to read ALL the fields for multiple products, so it could be any code related to them, especially computed field).EDIT: this call should raise the same error if I'm not wrong:
odoo.env['product.template'].read(product_ids, [])
Thank you @vcmanzo to confirm this.
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']
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']
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.