[FIX] account: don't use abs price in invoice report

The field price_subtotal_signed on an invoice line contains the line
subtotal:

- untouched if the invoice is of in_refund or out_invoice type,
- negated if the invoice is of in_invoice or out_refund type

At one point in time (not found), commit 649b289f using absolute value
of price_subtotal was introduced because price_subtotal_signed sometimes
had the wrong sign.

But this is source of an issue since it is possible to have an invoice with
two lines such as : 100€ and -20€, the report would then display 120, whilst
80 should have appeared.

This commit remove the use of absolute value, and if some old report data
(pre saas-6 migration with wrong migration script) are reported wrong
for an instance, it should be corrected manually.

opw-683952
closes #13118
This commit is contained in:
Nicolas Lempereur
2016-08-11 15:33:40 +02:00
parent cba50c30ab
commit 1924fb4bb9
@@ -114,7 +114,7 @@ class AccountInvoiceReport(models.Model):
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 * ail.quantity) / (u.factor * u2.factor)) AS product_qty,
SUM(invoice_type.sign * ABS(ail.price_subtotal_signed)) AS price_total,
SUM(ail.price_subtotal_signed) AS price_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)