fixes in gle_floating_point_issue patch
diff --git a/patches/february_2013/fix_outstanding.py b/patches/february_2013/fix_outstanding.py
index 07ea51a..22a6ee1 100644
--- a/patches/february_2013/fix_outstanding.py
+++ b/patches/february_2013/fix_outstanding.py
@@ -1,15 +1,24 @@
 def execute():
 	import webnotes
 	from webnotes.utils import flt
-	for dt in ["Sales Invoice", "Purchase Invoice"]:
-		records = webnotes.conn.sql("""select name, outstanding_amount from `tab%s` 
-			where docstatus = 1""" % dt)
-		for r in records:
-			outstanding = webnotes.conn.sql("""
-				select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) from `tabGL Entry`
-				where against_voucher = %s and against_voucher_type = %s 
-				and ifnull(is_cancelled, 'No') = 'No'""", (r[0], dt))
-			if flt(r[1]) != abs(flt(outstanding[0][0])):
-				# print r, outstanding
-				webnotes.conn.sql("update `tab%s` set outstanding_amount = %s where name = %s" %
-					(dt, '%s', '%s'), (abs(flt(outstanding[0][0])), r[0]))
\ No newline at end of file
+	records = webnotes.conn.sql("""
+		select against_voucher_type, against_voucher, 
+			sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) as outstanding from `tabGL Entry`
+		where ifnull(is_cancelled, 'No') = 'No' 
+		and against_voucher_type in ("Sales Invoice", "Purchase Invoice")
+		and ifnull(against_voucher, '') != ''
+		group by against_voucher_type, against_voucher""", as_dict=1)
+	for r in records:
+		outstanding = webnotes.conn.sql("""select name, outstanding_amount from `tab%s` 
+			where name = %s and docstatus = 1""" % 
+			(r["against_voucher_type"], '%s'), (r["against_voucher"]))
+			
+		if outstanding and abs(flt(r["outstanding"])) != flt(outstanding[0][1]):
+			if ((r["against_voucher_type"]=='Sales Invoice' and flt(r["outstanding"]) >= 0) \
+				or (r["against_voucher_type"]=="Purchase Invoice" and flt(["outstanding"]) <= 0)):
+				webnotes.conn.set_value(r["against_voucher_type"], r["against_voucher"], 
+					"outstanding_amount", abs(flt(r["outstanding"])))
+			else:
+				print r["against_voucher_type"], r["against_voucher"], \
+					outstanding[0][1], abs(flt(r["outstanding"]))
+		
\ No newline at end of file