summaryrefslogtreecommitdiff
path: root/addons/account/report
diff options
context:
space:
mode:
authorNans Lefebvre <len@odoo.com>2019-05-31 14:40:54 +0000
committerNans Lefebvre <len@odoo.com>2019-06-04 06:00:08 +0000
commit77da958be61e266ba535cdab3a8dad015f8fbc0f (patch)
tree4674d16964a2557a54acb007e427b5edaa5323d6 /addons/account/report
parent16f9375dab793b802fb13467d6b70821373d3df2 (diff)
[FIX] account_invoice_report: fix group by product
Group by invoice, products: the untaxed total is correct, while the (taxed) total is the sum of the lines divided by the number of lines. On account.invoice.line, there is a price_subtotal_signed, which is the price_subtotal (untaxed) in the company currency. Unfortunately price_total_signed does not exist for price_total (untaxed). As a result, we need to use the price_total on the invoice line, and divide by the currency rate. Unfortunately we cannot do it in the subquery because of the scope of the rate. opw 2003185 closes odoo/odoo#33802 Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
Diffstat (limited to 'addons/account/report')
-rw-r--r--addons/account/report/account_invoice_report.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py
index abc17743e61..614aba000ab 100644
--- a/addons/account/report/account_invoice_report.py
+++ b/addons/account/report/account_invoice_report.py
@@ -96,7 +96,7 @@ class AccountInvoiceReport(models.Model):
sub.payment_term_id, sub.uom_name, sub.currency_id, sub.journal_id,
sub.fiscal_position_id, sub.user_id, sub.company_id, sub.nbr, sub.invoice_id, sub.type, sub.state,
sub.categ_id, sub.date_due, sub.account_id, sub.account_line_id, sub.partner_bank_id,
- sub.product_qty, sub.price_total as price_total, sub.price_average as price_average, sub.amount_total as amount_total,
+ sub.product_qty, sub.price_total as price_total, sub.price_average as price_average, sub.amount_total / COALESCE(cr.rate, 1) as amount_total,
COALESCE(cr.rate, 1) as currency_rate, sub.residual as residual, sub.commercial_partner_id as commercial_partner_id
"""
return select_str
@@ -114,8 +114,7 @@ class AccountInvoiceReport(models.Model):
ai.partner_bank_id,
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(ail.price_total * invoice_type.sign_qty) AS amount_total,
SUM(ABS(ail.price_subtotal_signed)) / CASE
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))