diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index 42378e4e00c..6b509a5b384 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -220,31 +220,8 @@ class Pricelist(models.Model): # price_compute returns the price in the context UoM, i.e. qty_uom_id price = product.price_compute(rule.base)[product.id] - convert_to_price_uom = (lambda price: product.uom_id._compute_price(price, price_uom)) - if price is not False: - if rule.compute_price == 'fixed': - price = convert_to_price_uom(rule.fixed_price) - elif rule.compute_price == 'percentage': - price = (price - (price * (rule.percent_price / 100))) or 0.0 - else: - # complete formula - price_limit = price - price = (price - (price * (rule.price_discount / 100))) or 0.0 - if rule.price_round: - price = tools.float_round(price, precision_rounding=rule.price_round) - - if rule.price_surcharge: - price_surcharge = convert_to_price_uom(rule.price_surcharge) - price += price_surcharge - - if rule.price_min_margin: - price_min_margin = convert_to_price_uom(rule.price_min_margin) - price = max(price, price_limit + price_min_margin) - - if rule.price_max_margin: - price_max_margin = convert_to_price_uom(rule.price_max_margin) - price = min(price, price_limit + price_max_margin) + price = rule._compute_price(price, price_uom, product, quantity=qty, partner=partner) suitable_rule = rule break # Final price conversion into pricelist currency @@ -601,3 +578,33 @@ class PricelistItem(models.Model): self.flush() self.invalidate_cache() return res + + def _compute_price(self, price, price_uom, product, quantity=1.0, partner=False): + """Compute the unit price of a product in the context of a pricelist application. + The unused parameters are there to make the full context available for overrides. + """ + self.ensure_one() + convert_to_price_uom = (lambda price: product.uom_id._compute_price(price, price_uom)) + if self.compute_price == 'fixed': + price = convert_to_price_uom(self.fixed_price) + elif self.compute_price == 'percentage': + price = (price - (price * (self.percent_price / 100))) or 0.0 + else: + # complete formula + price_limit = price + price = (price - (price * (self.price_discount / 100))) or 0.0 + if self.price_round: + price = tools.float_round(price, precision_rounding=self.price_round) + + if self.price_surcharge: + price_surcharge = convert_to_price_uom(self.price_surcharge) + price += price_surcharge + + if self.price_min_margin: + price_min_margin = convert_to_price_uom(self.price_min_margin) + price = max(price, price_limit + price_min_margin) + + if self.price_max_margin: + price_max_margin = convert_to_price_uom(self.price_max_margin) + price = min(price, price_limit + price_max_margin) + return price