1
votes

I use the get_product_price_rule() function from 'product.pricelist' model. My code is:

price =  self._get_display_price(product)

The error log is:

File "/odoo/addons/sale/models/sale.py", line 875, in _get_display_price
    final_price1, rule_id1 = self.order_id.pricelist_id.with_context(product_context).get_product_price_rule(product,self.product_uom_qty or 1.0, self.order_id.partner_id)
  File "/odoo/addons/product/models/product_pricelist.py", line 264, in get_product_price_rule
    self.ensure_one()
  File "/odoo/odoo/models.py", line 4844, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: product.pricelist()

How to solve this error? My goal is to get the product display price. I need a solution and advice.

2
Please place your '_get_display_price' code - sfx
product.pricelist() is not giving a single record. Please edit your question with _get_display_price(). - PROTOCOL

2 Answers

2
votes

Your issue seems related that there is no pricelist on the sale order and as the error states, a singleton value it's expected. Normally this is related with a more than one value in the recordset but the same apply for no value in the recordset as one is expected.

Due to that, your issue could be solved with something like an if to check for the pricelist_id value on the self.order_id or you could find the default public pricelist to use it to calculate the product price, or simply use the product sale price when there is no value on self.order_id.pricelist_id

0
votes

By default a method in Odoo is decorated with @api.multi decorator.

This means self value is a list of RecordSet, not a RecordSet, so you have two solutions to solve this issue:

Option 1: Loop over the RecordSet list with

for record in self:
    price =  record._get_display_price(product)

Option 2: Check you have only one RecordSet in the list by using:

self.ensure_one()

You can get more documentation on https://odoo-new-api-guide-line.readthedocs.io/en/latest/environment.html#recordset