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()