blob: 226b360a29bdb03233b6875cb105791eae815b0a [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" %
15 (dt, '%s', '%s'), (abs(flt(outstanding[0][0])), si[0]))