[FIX] partner_statement: consider a multicurrency case

Detected cases where account_partial_reconcile has null currency_id, thus giving falsy amount_currency, and thus making some reconciled invoices appearing in the outstanding. Used _amount_residual of account move lines as reference to fix it.

partner_statement 13.0.1.2.1
This commit is contained in:
mreficent
2021-06-17 01:12:35 +02:00
committed by Miquel Raïch
parent f6c6ce950e
commit 286a330509
4 changed files with 135 additions and 100 deletions

View File

@@ -23,17 +23,16 @@ class ActivityStatement(models.AbstractModel):
ELSE sum(l.debit)
END as debit,
CASE WHEN l.currency_id is not null AND l.amount_currency < 0.0
THEN sum(l.amount_currency * (-1))
THEN sum(-l.amount_currency)
ELSE sum(l.credit)
END as credit
FROM account_move_line l
JOIN account_move m ON (l.move_id = m.id)
WHERE l.partner_id IN %(partners)s
AND l.account_internal_type = %(account_type)s
AND l.date < %(date_start)s AND not l.blocked
AND m.state IN ('posted')
GROUP BY l.partner_id, l.currency_id, l.amount_currency,
l.company_id
AND l.account_internal_type = %(account_type)s
AND l.date < %(date_start)s AND not l.blocked
AND m.state IN ('posted')
GROUP BY l.partner_id, l.currency_id, l.amount_currency, l.company_id
""",
locals(),
),