Skip to content
Snippets Groups Projects
Commit 1558bb2a authored by Andrea Grazioso (agr-odoo)'s avatar Andrea Grazioso (agr-odoo)
Browse files

[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#44654

Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent 03e25484
Branches
Tags
No related merge requests found
......@@ -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))
......
......@@ -114,8 +114,8 @@ class TestAccountInvoiceReport(InvoiceTestCommon):
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],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment