From b3fe75b2f3bcb5f41647f06f3baac51bb18fb0b8 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Tue, 16 Aug 2022 14:12:09 +0000 Subject: [PATCH] [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) --- addons/account/models/account_bank_statement.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index f71fd6f45cc..052d8017b6f 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -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: