From 0a187bece62f1f984220ce2bc3bd927e29ea24cb Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 25 Aug 2011 19:28:02 +0530 Subject: [PATCH] dashboard fixes --- home/page/dashboard/dashboard.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/home/page/dashboard/dashboard.py b/home/page/dashboard/dashboard.py index 940bb50b94..2f860dff8c 100644 --- a/home/page/dashboard/dashboard.py +++ b/home/page/dashboard/dashboard.py @@ -136,7 +136,7 @@ class DashboardWidget: select count(*) from `tab%s` where creation between %s and %s and docstatus=1 """ % (doctype, '%s','%s'), (start, end))[0][0]) - def get_account_amt(self, acc, start, end): + def get_account_amt(self, acc, start, end, debit_or_credit): """ Get debit, credit over a period """ @@ -154,9 +154,9 @@ class DashboardWidget: and t2.debit_or_credit=%s and ifnull(t1.is_cancelled, 'No')='No' and t1.posting_date between %s and %s - """, (acc=='Income' and 'Credit' or 'Debit', start, end))[0] + """, (debit_or_credit, start, end))[0] - return acc=='Income' and (ret[1]-ret[0]) or (ret[0]-ret[1]) + return debit_or_credit=='Credit' and (ret[1]-ret[0]) or (ret[0]-ret[1]) def value(self, opts, start, end): """ @@ -164,7 +164,11 @@ class DashboardWidget: """ import webnotes if opts['type']=='account': - bal = self.get_account_amt(opts['account'], start, end) + debit_or_credit = 'Debit' + if opts['account']=='Income': + debit_or_credit = 'Credit' + + return self.get_account_amt(opts['account'], start, end, debit_or_credit) elif opts['type']=='from_company': acc = webnotes.conn.get_value('Company', self.company, \ @@ -174,9 +178,9 @@ class DashboardWidget: elif opts['type']=='cash': if opts['debit_or_credit']=='Credit': - return sum([self.get_account_balance(acc, start)[1] for acc in self.cash_accounts]) or 0 + return sum([self.get_account_amt(acc, start, end, opts['debit_or_credit']) for acc in self.cash_accounts]) or 0 elif opts['debit_or_credit']=='Debit': - return sum([self.get_account_balance(acc, start)[0] for acc in self.cash_accounts]) or 0 + return sum([self.get_account_amt(acc, start, end, opts['debit_or_credit']) for acc in self.cash_accounts]) or 0 elif opts['type']=='creation': return self.get_creation_trend(opts['doctype'], start, end)