summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2020-08-19 13:48:39 +0000
committerLaurent Smet <las@odoo.com>2020-08-20 12:49:26 +0000
commit538b7f22cfdd39ce3dea66b36b46ced2de7ceaed (patch)
tree2bf45d529ae2f0f1dd38a9e37a98683c41a5887c
parentd6356f7c37aac68bf6d15ebb51de140e2acafc60 (diff)
[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>
-rw-r--r--addons/account/models/account_journal.py13
1 files 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