From 3a23a5740e78a87c5d8f36a8ab39d52155f58925 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 12 Dec 2011 19:50:09 +0530 Subject: [PATCH] In Dashboard, display a customer friendly error message when the start and end dates are not within a fiscal year --- erpnext/home/page/dashboard/dashboard.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/erpnext/home/page/dashboard/dashboard.py b/erpnext/home/page/dashboard/dashboard.py index 9ead6d688d..0dc2d6ddd4 100644 --- a/erpnext/home/page/dashboard/dashboard.py +++ b/erpnext/home/page/dashboard/dashboard.py @@ -133,19 +133,27 @@ class DashboardWidget: webnotes.msgprint('Wrongly defined account: ' + acc) print acc raise e - - return self.glc.get_as_on_balance(acc, self.get_fiscal_year(start), start, debit_or_credit, lft, rgt) + + fiscal_year = self.get_fiscal_year(start) + if fiscal_year: + return self.glc.get_as_on_balance(acc, fiscal_year, start, debit_or_credit, lft, rgt) + else: + webnotes.msgprint('Please select the START DATE and END DATE such that\ + they fall within the same fiscal year as defined in\ + Setup > System > Fiscal Year.', raise_exception=1) + def get_fiscal_year(self, dt): """ get fiscal year from date """ import webnotes - return webnotes.conn.sql(""" + fiscal_year = webnotes.conn.sql(""" select name from `tabFiscal Year` where year_start_date <= %s and DATE_ADD(year_start_date, INTERVAL 1 YEAR) >= %s - """, (dt, dt))[0][0] + """, (dt, dt)) + return fiscal_year and (fiscal_year[0] and fiscal_year[0][0]) or None def get_creation_trend(self, doctype, start, end): """ @@ -257,4 +265,4 @@ if __name__=='__main__': "start": "2011-05-01", "end": "2011-08-01", "interval": "7" - }""") \ No newline at end of file + }""")