[FIX] account: Fix constraint on bank/cash journals

Such stuff must be limited to bank/cash journals.

closes odoo/odoo#56184

X-original-commit: c1caf6a705c7ca02ef1c75fc36632af5055eda7a
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
Laurent Smet
2020-08-20 12:49:26 +00:00
parent d6356f7c37
commit 538b7f22cf
+8 -5
View File
@@ -266,9 +266,11 @@ class AccountJournal(models.Model):
@api.constrains('default_account_id', 'payment_debit_account_id', 'payment_credit_account_id')
def _check_journal_not_shared_accounts(self):
accounts = self.default_account_id \
+ self.payment_debit_account_id \
+ self.payment_credit_account_id
liquidity_journals = self.filtered(lambda journal: journal.type in ('bank', 'cash'))
accounts = liquidity_journals.default_account_id \
+ liquidity_journals.payment_debit_account_id \
+ liquidity_journals.payment_credit_account_id
if not accounts:
return
@@ -290,6 +292,7 @@ class AccountJournal(models.Model):
OR
journal.payment_credit_account_id = account.id
WHERE account.id IN %s
AND journal.type IN ('bank', 'cash')
GROUP BY account.name
HAVING COUNT(DISTINCT journal.id) > 1
''', [tuple(accounts.ids)])
@@ -386,8 +389,8 @@ class AccountJournal(models.Model):
raise UserError(_("You cannot modify the field %s of a journal that already has accounting entries.", field_string))
result = super(AccountJournal, self).write(vals)
for journal in self:
# Ensure the liquidity accounts are sharing the same foreign currency.
# Ensure the liquidity accounts are sharing the same foreign currency.
for journal in self.filtered(lambda journal: journal.type in ('bank', 'cash')):
journal.default_account_id.currency_id = journal.currency_id
# Create the bank_account_id if necessary