From e7318768906c76a8873c8dc20778994451fbacbf Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 20 Oct 2022 10:13:54 +0000 Subject: [PATCH] [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) --- addons/product/models/product_pricelist.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index 478d4293d21..6febbc26dd5 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -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