[FIX] account: avoid receivable accounts on bank journals
You cannot set a receivable or payable account as a bank account of a bank journal directly, but it is very possible to just set an account of another type, then change the type of this account to receivable. This new constrains will make sure that you cannot change the type of an account.account set as bank account on a bank journal to any of those two types. closes odoo/odoo#102790 X-original-commit: f9500ca4c898cd86681cc2e48ec2c66cf5670917 Related: odoo/enterprise#32579 Signed-off-by: Florian Gilbert (flg) <flg@odoo.com> Signed-off-by: Nicolas Viseur <vin@odoo.com>
This commit is contained in:
@@ -15039,6 +15039,14 @@ msgid ""
|
||||
"journal items."
|
||||
msgstr ""
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/models/account_account.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You cannot change the type of an account set as Bank Account on a journal to"
|
||||
" Receivable or Payable."
|
||||
msgstr ""
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/models/partner.py:0
|
||||
#, python-format
|
||||
|
||||
@@ -296,6 +296,21 @@ class AccountAccount(models.Model):
|
||||
"The account code can only contain alphanumeric characters and dots."
|
||||
))
|
||||
|
||||
@api.constrains('account_type')
|
||||
def _check_account_is_bank_journal_bank_account(self):
|
||||
self.env['account.account'].flush_model(['account_type'])
|
||||
self.env['account.journal'].flush_model(['type', 'default_account_id'])
|
||||
self._cr.execute('''
|
||||
SELECT journal.id
|
||||
FROM account_journal journal
|
||||
JOIN account_account account ON journal.default_account_id = account.id
|
||||
WHERE account.account_type IN ('asset_receivable', 'liability_payable')
|
||||
LIMIT 1;
|
||||
''', [tuple(self.ids)])
|
||||
|
||||
if self._cr.fetchone():
|
||||
raise ValidationError(_("You cannot change the type of an account set as Bank Account on a journal to Receivable or Payable."))
|
||||
|
||||
@api.depends('code')
|
||||
def _compute_account_root(self):
|
||||
# this computes the first 2 digits of the account.
|
||||
|
||||
Reference in New Issue
Block a user