From 673f064cba6da60439dbfabf4c1348452a979769 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Mon, 12 Feb 2024 12:49:35 +0100 Subject: [PATCH] [IMP] product: do not search items if no pricelist Rules always have a pricelist, so we can avoid an useless database query when we are computing the prices without any pricelist. Also makes sure that the modified context used for the pricelist items search is not propagated by enforcing the same context in the returned rules. closes odoo/odoo#153624 Signed-off-by: Victor Feyens (vfe) --- addons/product/models/product_pricelist.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index c2beda3501a..df89dced81c 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -219,12 +219,15 @@ class Pricelist(models.Model): # Split methods to ease (community) overrides def _get_applicable_rules(self, products, date, **kwargs): self and self.ensure_one() # self is at most one record + if not self: + return self.env['product.pricelist.item'] + # Do not filter out archived pricelist items, since it means current pricelist is also archived # We do not want the computation of prices for archived pricelist to always fallback on the Sales price # because no rule was found (thanks to the automatic orm filtering on active field) return self.env['product.pricelist.item'].with_context(active_test=False).search( self._get_applicable_rules_domain(products=products, date=date, **kwargs) - ) + ).with_context(self.env.context) def _get_applicable_rules_domain(self, products, date, **kwargs): self and self.ensure_one() # self is at most one record