From c00efede3b663c1c296eca3650f90ffe3548bc5c Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Tue, 10 Jan 2023 17:22:23 +0000 Subject: [PATCH] [FIX] pos_sale_margin: correctly compute margin when no cost is set Current behavior: If there was no cost set on a product, the margin couldn't be calculated for the PoS sale report. Steps to reproduce: - Install PoS and Sales - Create a product with no cost - Open a session and make an order with this item - Close the session and go to the PoS sale report - Add the margin measure to the report, and show the stats by product - The new product does not have any margin. opw-3120208 closes odoo/odoo#110429 X-original-commit: 9105f803095d7ddb07bc62ec1e2f2982215e273e Signed-off-by: Trinh Jacky (trj) Signed-off-by: Engels Robin (roen) --- addons/pos_sale_margin/report/sale_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/pos_sale_margin/report/sale_report.py b/addons/pos_sale_margin/report/sale_report.py index 42bd9615d38..9053ea8a32b 100644 --- a/addons/pos_sale_margin/report/sale_report.py +++ b/addons/pos_sale_margin/report/sale_report.py @@ -9,5 +9,5 @@ class SaleReport(models.Model): def _fill_pos_fields(self, additional_fields): values = super()._fill_pos_fields(additional_fields) - values['margin'] = 'SUM(l.price_subtotal - l.total_cost / CASE COALESCE(pos.currency_rate, 0) WHEN 0 THEN 1.0 ELSE pos.currency_rate END)' + values['margin'] = 'SUM(l.price_subtotal - COALESCE(l.total_cost,0) / CASE COALESCE(pos.currency_rate, 0) WHEN 0 THEN 1.0 ELSE pos.currency_rate END)' return values