[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) <vfe@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user