From 93ba6f7e0ebbcc1201015dd2ef55745173cdd342 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 31 Oct 2013 11:47:45 +0530 Subject: [PATCH] [fix] [minor] update outstanding amount --- accounts/doctype/gl_entry/gl_entry.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/accounts/doctype/gl_entry/gl_entry.py b/accounts/doctype/gl_entry/gl_entry.py index 0c11198be9..dfac6b6469 100644 --- a/accounts/doctype/gl_entry/gl_entry.py +++ b/accounts/doctype/gl_entry/gl_entry.py @@ -135,17 +135,18 @@ def check_freezing_date(posting_date, adv_adj=False): def update_outstanding_amt(account, against_voucher_type, against_voucher, on_cancel=False): # get final outstanding amt - bal = flt(webnotes.conn.sql("""select sum(debit) - sum(credit) from `tabGL Entry` + bal = flt(webnotes.conn.sql("""select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) + from `tabGL Entry` where against_voucher_type=%s and against_voucher=%s and account = %s""", (against_voucher_type, against_voucher, account))[0][0] or 0.0) if against_voucher_type == 'Purchase Invoice': bal = -bal elif against_voucher_type == "Journal Voucher": - against_voucher_amount = flt(webnotes.conn.sql("""select sum(debit) - sum(credit) + against_voucher_amount = flt(webnotes.conn.sql(""" + select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) from `tabGL Entry` where voucher_type = 'Journal Voucher' and voucher_no = %s and account = %s""", (against_voucher, account))[0][0]) - bal = against_voucher_amount + bal if against_voucher_amount < 0: bal = -bal