From 3ebfc9352b7c71635c3b9edc2efe0e48cbc7aa53 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Fri, 5 Mar 2021 16:27:47 +0000 Subject: [PATCH] [FIX] sale_stock_margin: compute product uom qty When confirming a SO, if a line uses a different UoM than the default UoM of the line product, the computed cost will be updated to the product unit cost. To reproduce the error: 1. In Settings, enable: - Units of Measure - Margins 2. Create a product P - Sales Price: $100 - No customer taxes - Cost: $50 - UoM: Units 3. Create a SO - Add P - Set the line UoM to 'Dozens' 4. Display the order line field "Cost" - [Note] As you can see, since UoM is 'Dozens': - Unit Price: $1200 - Cost: $600 5. Confirm the SO Error: Line cost becomes $50 (the cost of one P-product). Since the UoM of the line is 'Dozens', Cost should be $600 (as before confirming the SO). As a result, this error creates incorrect data in the margins (95.83% instead of 50%). OPW-2444335 closes odoo/odoo#67480 X-original-commit: 377f70ada0ec720aca055986ff19b8bbff84e33d Signed-off-by: Adrien Widart --- addons/sale_stock_margin/models/sale_order_line.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/sale_stock_margin/models/sale_order_line.py b/addons/sale_stock_margin/models/sale_order_line.py index 67e56b87e29..9ed4be62849 100644 --- a/addons/sale_stock_margin/models/sale_order_line.py +++ b/addons/sale_stock_margin/models/sale_order_line.py @@ -15,4 +15,6 @@ class SaleOrderLine(models.Model): lines_without_moves |= line elif line.product_id.categ_id.property_cost_method != 'standard': line.purchase_price = line.product_id.with_company(line.company_id)._compute_average_price(0, line.product_uom_qty, line.move_ids) + if line.product_uom and line.product_uom != line.product_id.uom_id: + line.purchase_price = line.product_id.uom_id._compute_price(line.purchase_price, line.product_uom) return super(SaleOrderLine, lines_without_moves)._compute_purchase_price()