From 538b7f22cfdd39ce3dea66b36b46ced2de7ceaed Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 19 Aug 2020 13:48:39 +0000 Subject: [PATCH] [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 Signed-off-by: Laurent Smet --- addons/account/models/account_journal.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index 310b394770e..13c418cc099 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -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