From 62876b09f9b32e17e6a8a82a86039fb7f8744f51 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 3 Jun 2015 08:52:24 +0200 Subject: [PATCH] [FIX] account: account_balance of journals having debit/credit accounts not set `default_debit_account_id` and `default_credit_account_id` are not required. The code computing the journal account balance should not rely on the fact it is. opw-641433 --- addons/account/account_journal_dashboard.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/account/account_journal_dashboard.py b/addons/account/account_journal_dashboard.py index f7cdd726a3e..0f4d3f0eeb5 100644 --- a/addons/account/account_journal_dashboard.py +++ b/addons/account/account_journal_dashboard.py @@ -151,11 +151,13 @@ class account_journal(models.Model): if not line.journal_entry_ids: number_to_reconcile += 1 # optimization to read sum of balance from account_move_line - query = """SELECT sum(balance) FROM account_move_line WHERE account_id in (%s, %s);""" - self.env.cr.execute(query, (self.default_debit_account_id.id, self.default_credit_account_id.id)) - query_results = self.env.cr.dictfetchall() - if query_results and query_results[0].get('sum') != None: - account_sum = query_results[0].get('sum') + account_ids = tuple(filter(None, [self.default_debit_account_id.id, self.default_credit_account_id.id])) + if account_ids: + query = """SELECT sum(balance) FROM account_move_line WHERE account_id in %s;""" + self.env.cr.execute(query, (account_ids,)) + query_results = self.env.cr.dictfetchall() + if query_results and query_results[0].get('sum') != None: + account_sum = query_results[0].get('sum') #TODO need to check if all invoices are in the same currency than the journal!!!! elif self.type in ['sale', 'purchase']: # optimization to find total and sum of invoice that are in draft, open state