From 38fd5f4eb9f7b72a317bb36d0fc47dadd4f23ea6 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Mon, 7 Dec 2020 16:02:32 +0000 Subject: [PATCH] [FIX] sale_stock_margin: compute purchase_price from correct company - Install sale_stock_margin - In a multi-company environment, create a Product (i.e. Product X) with a different Cost in each Company - Switch to Company that is not the main one - Create a SO with Product X - Make sure Cost (purchase_price) field is diplayed in Order Lines tab - Confirm SO After confirmation, the purchase_price of Product X switches from Cost configured for current Company to Cost configured for the main Company. opw-2389741 closes odoo/odoo#62997 X-original-commit: 82106350d3a7b82c6c529ae4ff9a2513ae34518e Signed-off-by: Anh Thao PHAM --- addons/sale_stock_margin/models/sale_order_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_stock_margin/models/sale_order_line.py b/addons/sale_stock_margin/models/sale_order_line.py index 522ac89a28f..70f744b7478 100644 --- a/addons/sale_stock_margin/models/sale_order_line.py +++ b/addons/sale_stock_margin/models/sale_order_line.py @@ -14,5 +14,5 @@ class SaleOrderLine(models.Model): if not line.move_ids: lines_without_moves |= line else: - line.purchase_price = line.product_id._compute_average_price(0, line.product_uom_qty, line.move_ids) + line.purchase_price = line.product_id.with_company(line.company_id)._compute_average_price(0, line.product_uom_qty, line.move_ids) return super(SaleOrderLine, lines_without_moves)._compute_purchase_price()