From 5c6640eb3ddb980e335ae65dcaacbd127c5e298d Mon Sep 17 00:00:00 2001 From: csnauwaert Date: Thu, 29 Sep 2022 12:50:50 +0000 Subject: [PATCH] [FIX] account: add latest running balance when grouping by in statement list view In the list view of bank statement, when we group by statement or date or journal, we would like to be able to see the latest running balance in the groupby line. That way we can easily see the "ending balance" of each statement which is a huge help for the accountant closes odoo/odoo#101812 X-original-commit: 002709b75cf3516a7cdc1c2412afa02f40043abf Related: odoo/enterprise#32127 Signed-off-by: Laurent Smet Signed-off-by: Cedric Snauwaert --- .../models/account_bank_statement_line.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/addons/account/models/account_bank_statement_line.py b/addons/account/models/account_bank_statement_line.py index 49f999c1e4e..caca8af57e5 100644 --- a/addons/account/models/account_bank_statement_line.py +++ b/addons/account/models/account_bank_statement_line.py @@ -364,6 +364,23 @@ class AccountBankStatementLine(models.Model): moves.unlink() return res + @api.model + def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): + # Add latest running_balance in the read_group + result = super(AccountBankStatementLine, self).read_group( + domain, fields, groupby, offset=offset, + limit=limit, orderby=orderby, lazy=lazy) + show_running_balance = False + # We loop over the content of groupby because the groupby date is in the form of "date:granularity" + for el in groupby: + if (el == 'statement_id' or el == 'journal_id' or el.startswith('date')) and 'running_balance' in fields: + show_running_balance = True + break + if show_running_balance: + for group_line in result: + group_line['running_balance'] = self.search(group_line.get('__domain'), limit=1).running_balance or 0.0 + return result + # ------------------------------------------------------------------------- # ACTION METHODS # -------------------------------------------------------------------------