Nabin Hait | 362455e | 2013-02-13 15:50:39 +0530 | [diff] [blame] | 1 | def 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])) |