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'" \