[FIX] account: fix account type constraint on bank journals

The issue here is to be able to change the type of bank account
on the bank journal, e.g. changing from type "Current Assets" to "Bank and Cash".

Previously, a ValidationError would be raised :
"This account is configured in %(journal_names)s journal(s) (ids %(journal_ids)s)
as payment debit or credit account.
This means that this account's type should be reconcilable."

But in some cases, the client might decided not to reconcile.
And the error did not take into account the case when the bank account
and the outstanding accounts are the same.

opw-2738777

closes odoo/odoo#85370

X-original-commit: fe379bc22e649c623dfb6ed8aefb106b4846d02e
Signed-off-by: Laurent Smet <las@odoo.com>
Signed-off-by: John Laterre <jol@odoo.com>
This commit is contained in:
John Laterre (jol)
2022-02-24 20:29:38 +00:00
parent 2eccc43669
commit b0eed54cd0
+10 -3
View File
@@ -246,9 +246,16 @@ class AccountAccount(models.Model):
FROM account_journal journal
JOIN res_company company on journal.company_id = company.id
LEFT JOIN account_payment_method_line apml ON journal.id = apml.journal_id
WHERE company.account_journal_payment_credit_account_id in %(accounts)s
OR company.account_journal_payment_debit_account_id in %(accounts)s
OR apml.payment_account_id in %(accounts)s
WHERE (
company.account_journal_payment_credit_account_id IN %(accounts)s
AND company.account_journal_payment_credit_account_id != journal.default_account_id
) OR (
company.account_journal_payment_debit_account_id in %(accounts)s
AND company.account_journal_payment_debit_account_id != journal.default_account_id
) OR (
apml.payment_account_id IN %(accounts)s
AND apml.payment_account_id != journal.default_account_id
)
''', {
'accounts': tuple(accounts.ids),
})