From 4a29f76d032787e195d6e13bd8ed80a920cbb193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Fri, 4 Oct 2024 09:58:04 +0200 Subject: [PATCH 1/2] [FIX] account_statement_base: Allow remove lines from bank statment form view Fixes https://github.com/OCA/account-reconcile/issues/697 TT50906 --- .../models/account_bank_statement_line.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/account_statement_base/models/account_bank_statement_line.py b/account_statement_base/models/account_bank_statement_line.py index 857619b91b..4199a73fd2 100644 --- a/account_statement_base/models/account_bank_statement_line.py +++ b/account_statement_base/models/account_bank_statement_line.py @@ -7,6 +7,13 @@ class AccountBankStatementLine(models.Model): _inherit = "account.bank.statement.line" + # TODO: Delete if merged https://github.com/odoo/odoo/pull/182497 + def _compute_running_balance(self): + # We need to set value to all records because super() does not do it using sql. + for item in self: + item.running_balance = item.running_balance + return super()._compute_running_balance() + def action_open_journal_entry(self): self.ensure_one() if not self: From 79416011c4566ae6ca012f99bc14c280faecb4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Fri, 4 Oct 2024 10:07:41 +0200 Subject: [PATCH 2/2] [FIX] account_statement_base: Allow add lines from bank statment form view TT50906 --- .../models/account_bank_statement.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/account_statement_base/models/account_bank_statement.py b/account_statement_base/models/account_bank_statement.py index 5dcae41d8d..c9a608234f 100644 --- a/account_statement_base/models/account_bank_statement.py +++ b/account_statement_base/models/account_bank_statement.py @@ -4,6 +4,25 @@ class AccountBankStatement(models.Model): _inherit = "account.bank.statement" + # TODO: Delete if merged https://github.com/odoo/odoo/pull/182497 + def _compute_date_index(self): + """The super() method does not take into account lines that do not have + internal_index set yet, and causes sorted() to fail, we need to re-define + the method in these cases to avoid the error. + """ + _self = self + for stmt in self: + if any(not line.internal_index for line in stmt.line_ids): + _self -= stmt + sorted_lines = stmt.line_ids.filtered("internal_index").sorted( + "internal_index" + ) + stmt.first_line_index = sorted_lines[:1].internal_index + stmt.date = sorted_lines.filtered(lambda line: line.state == "posted")[ + -1: + ].date + return super(AccountBankStatement, _self)._compute_date_index() + def action_open_statement_lines(self): self.ensure_one() if not self: