[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>
This commit is contained in:
@@ -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(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],
|
||||
|
||||
Reference in New Issue
Block a user