From dc76823a8131fd5191c11f3230fbb74967863cb6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 17 Aug 2015 11:27:00 +0530 Subject: [PATCH] [fix] Get Balance only if account or party mentioned --- erpnext/accounts/utils.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index f41d19dddd..51c79160c7 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -100,14 +100,15 @@ def get_balance_on(account=None, date=None, party_type=None, party=None): if party_type and party: cond.append("""gle.party_type = "%s" and gle.party = "%s" """ % (party_type.replace('"', '\\"'), party.replace('"', '\\"'))) + + if account or (party_type and party): + bal = frappe.db.sql(""" + SELECT sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) + FROM `tabGL Entry` gle + WHERE %s""" % " and ".join(cond))[0][0] - bal = frappe.db.sql(""" - SELECT sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) - FROM `tabGL Entry` gle - WHERE %s""" % " and ".join(cond))[0][0] - - # if bal is None, return 0 - return flt(bal) + # if bal is None, return 0 + return flt(bal) @frappe.whitelist() def add_ac(args=None):