From 9365b616b831f4246bc73961c6752ccf4f3c5352 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 21 Apr 2014 12:42:21 +0530 Subject: [PATCH] Added an exist check for accounts.utils.get_balance_on --- erpnext/accounts/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index be29f349450..4eb5045038c 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -46,6 +46,12 @@ def get_balance_on(account=None, date=None): account = frappe.form_dict.get("account") date = frappe.form_dict.get("date") + acc = frappe.db.get_value('Account', account, \ + ['lft', 'rgt', 'report_type', 'group_or_ledger'], as_dict=1) + + if not acc: + frappe.throw(_("Account {0} does not exist").format(account), frappe.DoesNotExistError) + cond = [] if date: cond.append("posting_date <= '%s'" % date) @@ -65,9 +71,6 @@ def get_balance_on(account=None, date=None): # hence, assuming balance as 0.0 return 0.0 - acc = frappe.db.get_value('Account', account, \ - ['lft', 'rgt', 'report_type', 'group_or_ledger'], as_dict=1) - # for pl accounts, get balance within a fiscal year if acc.report_type == 'Profit and Loss': cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" \