[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) <vin@odoo.com>
This commit is contained in:
Florent de Labarre
2023-02-07 13:34:55 +01:00
committed by Nicolas (vin)
parent 14cb5ef420
commit caea280566
+2 -2
View File
@@ -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),