diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 1c189862f5b..48ed3e1def4 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3571,12 +3571,18 @@ class AccountMoveLine(models.Model): if account_currency and account_currency != line.company_currency_id and account_currency != line.currency_id: raise UserError(_('The account selected on your journal entry forces to provide a secondary currency. You should remove the secondary currency on the account.')) - control_journal_failed = account.allowed_journal_ids and journal not in account.allowed_journal_ids - control_type_failed = journal.type_control_ids and account.user_type_id not in journal.type_control_ids - control_account_failed = journal.account_control_ids and account not in journal.account_control_ids - if control_journal_failed: + if account.allowed_journal_ids and journal not in account.allowed_journal_ids: raise UserError(_('You cannot use this account (%s) in this journal, check the field \'Allowed Journals\' on the related account.', account.display_name)) - if control_type_failed or control_account_failed: + + failed_check = False + if journal.type_control_ids or journal.account_control_ids: + failed_check = True + if journal.type_control_ids: + failed_check = account.user_type_id not in journal.type_control_ids + if failed_check and journal.account_control_ids: + failed_check = account not in journal.account_control_ids + + if failed_check: raise UserError(_('You cannot use this account (%s) in this journal, check the section \'Control-Access\' under tab \'Advanced Settings\' on the related journal.', account.display_name)) @api.constrains('account_id', 'tax_ids', 'tax_line_id', 'reconciled')