[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 <las@odoo.com> Signed-off-by: Cedric Snauwaert <csn@odoo.com>
This commit is contained in:
@@ -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
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user