summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Grazioso (agr-odoo) <agr@odoo.com>2020-08-25 09:05:53 +0000
committerAndrea Grazioso (agr-odoo) <agr@odoo.com>2020-08-27 10:34:07 +0000
commite6c2dc3eb19a4e75d78b89529948533007dd8f69 (patch)
treec524c24f056c2034af85ba5733c154e4e3d8681b
parentd64b68cc04dabfb3f94b05cd181c216550a07c9e (diff)
[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#56642 X-original-commit: e932df3b356752eb9c42164821acb6e2db7fe317 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com> Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
-rw-r--r--addons/account/models/account_bank_statement.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py
index 9ca5d54d708..2e470c69ec8 100644
--- a/addons/account/models/account_bank_statement.py
+++ b/addons/account/models/account_bank_statement.py
@@ -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()