blob: 07ea51a695cabdfd91c64e121e7b244330711f81 [file] [log] [blame]
Nabin Hait362455e2013-02-13 15:50:39 +05301def execute():
2 import webnotes
3 from webnotes.utils import flt
4 for dt in ["Sales Invoice", "Purchase Invoice"]:
5 records = webnotes.conn.sql("""select name, outstanding_amount from `tab%s`
6 where docstatus = 1""" % dt)
7 for r in records:
8 outstanding = webnotes.conn.sql("""
9 select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) from `tabGL Entry`
10 where against_voucher = %s and against_voucher_type = %s
11 and ifnull(is_cancelled, 'No') = 'No'""", (r[0], dt))
12 if flt(r[1]) != abs(flt(outstanding[0][0])):
13 # print r, outstanding
14 webnotes.conn.sql("update `tab%s` set outstanding_amount = %s where name = %s" %
Anand Doshie74a1f22013-02-14 13:38:12 +053015 (dt, '%s', '%s'), (abs(flt(outstanding[0][0])), r[0]))