From caea280566b7d5a2b47d8654ab43ba9367e57d25 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Fri, 27 Jan 2023 09:24:56 +0000 Subject: [PATCH] [FIX] account: can't get previous move In case of a user have no access to all account.move (restrict by ir.rules). An exception can raise during move posting. Add an index to speed up this function in large database. OPW #3159258 closes odoo/odoo#112081 X-original-commit: 5b95336470efc7b92289936c29cf561ba5fb7f66 Signed-off-by: Nicolas Viseur (vin) --- addons/account/models/account_move.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index efc38f5115a..de72d8e4f36 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -240,7 +240,7 @@ class AccountMove(models.Model): # === Hash Fields === # restrict_mode_hash_table = fields.Boolean(related='journal_id.restrict_mode_hash_table') - secure_sequence_number = fields.Integer(string="Inalteralbility No Gap Sequence #", readonly=True, copy=False) + secure_sequence_number = fields.Integer(string="Inalteralbility No Gap Sequence #", readonly=True, copy=False, index=True) inalterable_hash = fields.Char(string="Inalterability Hash", readonly=True, copy=False) string_to_hash = fields.Char(compute='_compute_string_to_hash', readonly=True) @@ -2631,7 +2631,7 @@ class AccountMove(models.Model): """ Returns the hash to write on journal entries when they get posted""" self.ensure_one() #get the only one exact previous move in the securisation sequence - prev_move = self.search([('state', '=', 'posted'), + prev_move = self.sudo().search([('state', '=', 'posted'), ('company_id', '=', self.company_id.id), ('journal_id', '=', self.journal_id.id), ('secure_sequence_number', '!=', 0),