diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index 9133d8c9f15..1885aa8791b 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -546,8 +546,8 @@ class AccountJournal(models.Model): if bank_account.partner_id != company.partner_id: raise UserError(_("The partners of the journal's company and the related bank account mismatch.")) if 'restrict_mode_hash_table' in vals and not vals.get('restrict_mode_hash_table'): - journal_entry = self.env['account.move'].search([('journal_id', '=', self.id), ('state', '=', 'posted'), ('secure_sequence_number', '!=', 0)], limit=1) - if len(journal_entry) > 0: + journal_entry = self.env['account.move'].sudo().search([('journal_id', '=', self.id), ('state', '=', 'posted'), ('secure_sequence_number', '!=', 0)], limit=1) + if journal_entry: field_string = self._fields['restrict_mode_hash_table'].get_description(self.env)['string'] raise UserError(_("You cannot modify the field %s of a journal that already has accounting entries.", field_string)) result = super(AccountJournal, self).write(vals)