[IMP] product: do not compute pricelist price when not needed

For the sale scope, we added a new 'pricelist_item_id' field, caching
the pricelist rule used for the price_unit and discount computation.

This feature uses the new `_get_pricelist_rule` method, which only returns
the pricelist rule matching the SOline values.

But the `_get_pricelist_rule` method still does all the price computation
for 'nothing'.

This commit skips the price computation (and the search of sub-rules if
the rule found is based on another pricelist).

closes odoo/odoo#103629

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2022-10-20 16:15:57 +02:00
parent 107de3fceb
commit e731876890
+8 -4
View File
@@ -107,10 +107,10 @@ class Pricelist(models.Model):
"""
self.ensure_one()
return self._compute_price_rule(
product, quantity, uom=uom, date=date, **kwargs
product, quantity, uom=uom, date=date, compute_price=False, **kwargs
)[product.id][1]
def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs):
def _compute_price_rule(self, products, qty, uom=None, date=False, compute_price=True, **kwargs):
""" Low-level method - Mono pricelist, multi products
Returns: dict{product_id: (price, suitable_rule) for the given pricelist}
@@ -120,6 +120,7 @@ class Pricelist(models.Model):
If not specified, prices returned are expressed in product uoms
:param date: date to use for price computation and currency conversions
:type date: date or datetime
:param bool compute_price: whether the price should be computed (default: True)
:returns: product_id: (price, pricelist_rule)
:rtype: dict
@@ -155,8 +156,11 @@ class Pricelist(models.Model):
suitable_rule = rule
break
kwargs['pricelist'] = self
price = suitable_rule._compute_price(product, qty, target_uom, date=date, currency=self.currency_id)
if compute_price:
price = suitable_rule._compute_price(product, qty, target_uom, date=date, currency=self.currency_id)
else:
# Skip price computation when only the rule is requested.
price = 0.0
results[product.id] = (price, suitable_rule.id)
return results