[FIX] account: recursive computation with out-of-order bank statement

Have a sequence of bank statement out of order
i.e.
|id|  date  |
|--|--------|
|01|20/07/22|
|02|21/07/22|
|03|22/07/22|
|04|18/07/22|
|05|17/07/22|
|06|16/07/22|
|07|15/07/22|

Adding more out-of-order bank statement will trigger recomputation in
all the next (chronologically) statements.
As the records to recompute are ordered by id, it may occur that the
first statements to recompute have the highest date and cause a
recomputation recursion exceeding the limits

opw-2925984

closes odoo/odoo#98373

X-original-commit: f675222786a9f57199117d38fca529dd1b0c2104
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2022-08-18 15:08:10 +02:00
committed by Nicolas Martinelli
parent 162f783d34
commit b3fe75b2f3
@@ -120,7 +120,11 @@ class AccountBankStatement(models.Model):
# won't be called and therefore the other field will have a value of 0 and we don't want that.
@api.depends('previous_statement_id', 'previous_statement_id.balance_end_real')
def _compute_starting_balance(self):
for statement in self:
# When a bank statement is inserted out-of-order several fields needs to be recomputed.
# As the records to recompute are ordered by id, it may occur that the first record
# to recompute start a recursive recomputation of field balance_end_real
# To avoid this we sort the records by date
for statement in self.sorted(key=lambda s: s.date):
if statement.previous_statement_id.balance_end_real != statement.balance_start:
statement.balance_start = statement.previous_statement_id.balance_end_real
else: