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 # -------------------------------------------------------------------------