diff options
| author | Andrea Grazioso (agr-odoo) <agr@odoo.com> | 2020-02-05 13:06:33 +0000 |
|---|---|---|
| committer | Andrea Grazioso (agr-odoo) <agr@odoo.com> | 2020-02-11 09:16:03 +0000 |
| commit | 825b227d5c51a080563ef8f34c5942c6e22aaf21 (patch) | |
| tree | cf4094a8e7073ecacd49a4e9fa7da54c7276a8df | |
| parent | 479cb5bfcd87bf9210d2314adcd5798680d5ed70 (diff) | |
[FIX] account: fix invoice report total incorrect
Go to Accounting / Reporting / Management / Invoices
Select Pivot view
Add "Total" measure
expand results adding "invoice #" and product
Total will be incorrect because it is summing up the value reported from
several lines of the query in which the total is taken as the invoice
total, so it will display total * # lines.
Using the price retrieved from the single lines fix the issue, but it
needs to be converted according to the currency rate of the invoice.
Moreover the test need to be modified because the amount_total variable
of the report should NOT be the move amount_total but the amount from
all the lines converted in company currency
opw-2187369
closes odoo/odoo#45050
X-original-commit: 1558bb2a62cf169e6b19a2aa4dd92fcd8ff1b25a
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
| -rw-r--r-- | addons/account/report/account_invoice_report.py | 22 | ||||
| -rw-r--r-- | addons/account/tests/test_account_invoice_report.py | 4 |
2 files changed, 23 insertions, 3 deletions
diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index e9e960872fd..3ef358a9093 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -98,7 +98,27 @@ class AccountInvoiceReport(models.Model): move.invoice_payment_term_id, move.invoice_partner_bank_id, move.amount_residual_signed AS residual, - move.amount_total_signed AS amount_total, + ROUND( + line.price_total / COALESCE( + (SELECT rate FROM res_currency_rate cr WHERE + cr.currency_id = line.currency_id AND + cr.company_id = line.company_id AND + cr.name <= COALESCE(line.date,NOW()) + ORDER BY cr.name DESC + LIMIT 1) + ,1), + COALESCE((SELECT decimal_places + FROM res_currency rc INNER JOIN res_currency_rate cr ON + rc.id = cr.currency_id + WHERE cr.currency_id = (COALESCE(line.currency_id, line.company_currency_id)) AND + cr.company_id = line.company_id + LIMIT 1 + ),2)) + * + (CASE WHEN move.amount_total_signed < 0 + THEN -1 + ELSE 1 + END) AS amount_total, uom_template.id AS product_uom_id, template.categ_id AS product_categ_id, SUM(line.quantity / NULLIF(COALESCE(uom_line.factor, 1) * COALESCE(uom_template.factor, 1), 0.0)) diff --git a/addons/account/tests/test_account_invoice_report.py b/addons/account/tests/test_account_invoice_report.py index bc4d6e2e27b..a794b2a4b6b 100644 --- a/addons/account/tests/test_account_invoice_report.py +++ b/addons/account/tests/test_account_invoice_report.py @@ -114,8 +114,8 @@ class TestAccountInvoiceReport(AccountTestInvoicingCommon): self.assertInvoiceReportValues([ # amount_total price_average price_subtotal residual quantity [2000, 2000, 2000, 2000, 1], - [2000, 1000, 1000, 2000, 1], - [2000, 1000, 1000, 2000, 3], + [1000, 1000, 1000, 2000, 1], + [1000, 1000, 1000, 2000, 3], [6, 6, 6, 6, 1], [-20, -20, -20, -20, 1], [-20, -20, -20, -20, 1], |
