[FIX] account: avoid long recomputation recursion

when creating the first bank statement on a journal. It will trigger
manual field recomputations:
https://github.com/odoo/odoo/blob/d19477f982e046ba563ce18706f0eab2b250738d/addons/account/models/account_bank_statement.py#L288-L297

previous_statement_id will correctly be False
The manual recomputation in create will recalculate all bank
statements that have a False previous_statement_id.
These bank statements are usually the first ones in a journal. When they get
recomputed it triggers recomputations for every bank statement that
follows it.

This commit try to limit this behavior by recomputing statements only in
the same journal

opw-2311173

closes odoo/odoo#56648

X-original-commit: e932df3b356752eb9c42164821acb6e2db7fe317
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2020-08-27 10:59:31 +00:00
parent b82723fb22
commit 9fa270c70b
@@ -253,11 +253,11 @@ class AccountBankStatement(models.Model):
# by marking those record as needing to be recomputed.
# Note that marking the field is not enough as we also have to recompute all its other fields that are depending on 'previous_statement_id'
# hence the need to call modified afterwards.
to_recompute = self.search([('previous_statement_id', 'in', self.ids), ('id', 'not in', self.ids)])
to_recompute = self.search([('previous_statement_id', 'in', self.ids), ('id', 'not in', self.ids), ('journal_id', 'in', self.mapped('journal_id').ids)])
if to_recompute:
self.env.add_to_compute(self._fields['previous_statement_id'], to_recompute)
to_recompute.modified(['previous_statement_id'])
next_statements_to_recompute = self.search([('previous_statement_id', 'in', [st.previous_statement_id.id for st in self]), ('id', 'not in', self.ids)])
next_statements_to_recompute = self.search([('previous_statement_id', 'in', [st.previous_statement_id.id for st in self]), ('id', 'not in', self.ids), ('journal_id', 'in', self.mapped('journal_id').ids)])
if next_statements_to_recompute:
self.env.add_to_compute(self._fields['previous_statement_id'], next_statements_to_recompute)
next_statements_to_recompute.modified(['previous_statement_id'])
@@ -272,7 +272,7 @@ class AccountBankStatement(models.Model):
# Note that marking the field is not enough as we also have to recompute all its other fields that are depending on 'previous_statement_id'
# hence the need to call modified afterwards.
# The reason we are doing this here and not in a compute field is that it is not easy to write dependencies for such field.
next_statements_to_recompute = self.search([('previous_statement_id', 'in', [st.previous_statement_id.id for st in res]), ('id', 'not in', res.ids)])
next_statements_to_recompute = self.search([('previous_statement_id', 'in', [st.previous_statement_id.id for st in res]), ('id', 'not in', res.ids), ('journal_id', 'in', res.journal_id.ids)])
if next_statements_to_recompute:
self.env.add_to_compute(self._fields['previous_statement_id'], next_statements_to_recompute)
next_statements_to_recompute.modified(['previous_statement_id'])
@@ -336,7 +336,7 @@ class AccountBankStatement(models.Model):
statement.line_ids.unlink()
# Some other bank statements might be link to this one, so in that case we have to switch the previous_statement_id
# from that statement to the one linked to this statement
next_statement = self.search([('previous_statement_id', '=', statement.id)])
next_statement = self.search([('previous_statement_id', '=', statement.id), ('journal_id', '=', statement.journal_id.id)])
if next_statement:
next_statement.previous_statement_id = statement.previous_statement_id
return super(AccountBankStatement, self).unlink()