From 6c211376f0faa9c72213a2efe2ea1b726d247678 Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Fri, 19 Jan 2018 16:13:54 +0100 Subject: [PATCH] [IMP] account: include only posted entries in the GL balance of bank/cash journals special request from Gustavo Valverde. Was github issue #22383. --- addons/account/models/account_journal_dashboard.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index 1c263bb41e8..b1cd6c09eb9 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -167,8 +167,11 @@ class account_journal(models.Model): # optimization to read sum of balance from account_move_line account_ids = tuple(ac for ac in [self.default_debit_account_id.id, self.default_credit_account_id.id] if ac) if account_ids: - amount_field = 'balance' if (not self.currency_id or self.currency_id == self.company_id.currency_id) else 'amount_currency' - query = """SELECT sum(%s) FROM account_move_line WHERE account_id in %%s AND date <= %%s;""" % (amount_field,) + amount_field = 'aml.balance' if (not self.currency_id or self.currency_id == self.company_id.currency_id) else 'aml.amount_currency' + query = """SELECT sum(%s) FROM account_move_line aml + LEFT JOIN account_move move ON aml.move_id = move.id + WHERE aml.account_id in %%s + AND move.date <= %%s AND move.state = 'posted';""" % (amount_field,) self.env.cr.execute(query, (account_ids, fields.Date.today(),)) query_results = self.env.cr.dictfetchall() if query_results and query_results[0].get('sum') != None: