From 418babf7af7b52ba3aef120de9be49dea9669b74 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Fri, 17 May 2019 12:22:58 +0000 Subject: [PATCH] [FIX] account: Invoice Analysis product quantity To calculate the product quantity and the average price, two UOM are used: The UOM of the product, and the UOM of the invoice line. The UOM of the product it's mandatory in the product, but the product itself it's not mandatory in the invoice. The UOM of the invoice line it's not mandatory. When either of the UOM is not filled, it gives as value NULL, and gives 'empty' as result of the calculation. Now, we use the psql function COALESCE to return '1' when one of the UOM is not filled. closes odoo/odoo#33465 Signed-off-by: Nicolas Martinelli (nim) --- addons/account/report/account_invoice_report.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index 99b79387eb7..abc17743e61 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -112,13 +112,13 @@ class AccountInvoiceReport(models.Model): 1 AS nbr, ai.id AS invoice_id, ai.type, ai.state, pt.categ_id, ai.date_due, ai.account_id, ail.account_id AS account_line_id, ai.partner_bank_id, - SUM ((invoice_type.sign_qty * ail.quantity) / u.factor * u2.factor) AS product_qty, + SUM ((invoice_type.sign_qty * ail.quantity) / COALESCE(u.factor,1) * COALESCE(u2.factor,1)) AS product_qty, SUM(ail.price_subtotal_signed * invoice_type.sign) AS price_total, ai.amount_total_signed / (SELECT count(*) FROM account_invoice_line l where invoice_id = ai.id) * count(*) * invoice_type.sign AS amount_total, SUM(ABS(ail.price_subtotal_signed)) / CASE - WHEN SUM(ail.quantity / u.factor * u2.factor) <> 0::numeric - THEN SUM(ail.quantity / u.factor * u2.factor) + WHEN SUM(ail.quantity / COALESCE(u.factor,1) * COALESCE(u2.factor,1)) <> 0::numeric + THEN SUM(ail.quantity / COALESCE(u.factor,1) * COALESCE(u2.factor,1)) ELSE 1::numeric END AS price_average, ai.residual_company_signed / (SELECT count(*) FROM account_invoice_line l where invoice_id = ai.id) *