diff --git a/product_pack/models/product_pack_line.py b/product_pack/models/product_pack_line.py index b61a6dba3..e605f2603 100644 --- a/product_pack/models/product_pack_line.py +++ b/product_pack/models/product_pack_line.py @@ -54,13 +54,18 @@ def _check_recursion(self): ) pack_lines = pack_lines.mapped("product_id.pack_line_ids") - def price_compute( + def _pack_line_price_compute( self, price_type, uom=False, currency=False, company=False, date=False ): - pack_line_prices = self.product_id.price_compute( - price_type, uom, currency, company, date - ) - for line in self: - pack_line_prices[line.product_id.id] *= line.quantity + pack_line_prices = {} + if self._context.get('pricelist'): + for line in self: + pack_line_prices[line.product_id.id] = line.with_context(quantity=line.quantity).product_id._get_contextual_price() + else: + pack_line_prices = self.product_id.price_compute( + price_type, uom, currency, company, date + ) + for line in self: + pack_line_prices[line.product_id.id] *= line.quantity return pack_line_prices diff --git a/product_pack/models/product_product.py b/product_pack/models/product_product.py index a7b52960e..b040a4314 100644 --- a/product_pack/models/product_product.py +++ b/product_pack/models/product_product.py @@ -39,7 +39,7 @@ def price_compute( ) # TODO:@bruno-zanotti prefetch_fields=False still necessary? for product in packs.with_context(prefetch_fields=False): - pack_line_prices = product.sudo().pack_line_ids.price_compute( + pack_line_prices = product.sudo().pack_line_ids._pack_line_price_compute( price_type, uom, currency, company, date ) prices[product.id] = sum(pack_line_prices.values()) diff --git a/sale_product_pack/models/product_pack_line.py b/sale_product_pack/models/product_pack_line.py index d187de27d..ea93d255d 100644 --- a/sale_product_pack/models/product_pack_line.py +++ b/sale_product_pack/models/product_pack_line.py @@ -38,10 +38,10 @@ def get_sale_order_line_vals(self, line, order): return vals - def price_compute( + def _pack_line_price_compute( self, price_type, uom=False, currency=False, company=False, date=False ): - pack_line_prices = super().price_compute( + pack_line_prices = super()._pack_line_price_compute( price_type, uom, currency, company, date ) for line in self: diff --git a/sale_product_pack/models/sale_order.py b/sale_product_pack/models/sale_order.py index ea6ed0639..590f6f622 100644 --- a/sale_product_pack/models/sale_order.py +++ b/sale_product_pack/models/sale_order.py @@ -64,3 +64,6 @@ def _get_update_prices_lines(self): lambda line: not line.pack_parent_line_id or line.pack_parent_line_id.pack_component_price == "detailed" ) + + def action_update_prices(self): + super(SaleOrder, self.with_context(pricelist=self.pricelist_id.id)).action_update_prices()