nabinhait | 690c697 | 2011-06-28 14:42:07 +0530 | [diff] [blame] | 1 | import webnotes |
| 2 | sql = webnotes.conn.sql |
| 3 | |
| 4 | # update SO |
| 5 | #--------------- |
| 6 | def update_percent(): |
| 7 | so = sql("select name from `tabSales Order` where docstatus = 1") |
| 8 | for d in so: |
| 9 | sql(""" |
| 10 | update |
| 11 | `tabSales Order` |
| 12 | set |
| 13 | per_delivered = (select sum(if(qty > ifnull(delivered_qty, 0), delivered_qty, qty))/sum(qty)*100 from `tabSales Order Detail` where parent='%s'), |
| 14 | per_billed = (select sum(if(qty > ifnull(billed_qty, 0), billed_qty, qty))/sum(qty)*100 from `tabSales Order Detail` where parent='%s') |
| 15 | where |
| 16 | name='%s'""" % (d[0], d[0], d[0])) |
| 17 | |
| 18 | # update DN |
| 19 | # --------- |
| 20 | dn = sql("select name from `tabDelivery Note` where docstatus = 1") |
| 21 | for d in dn: |
| 22 | sql(""" |
| 23 | update |
| 24 | `tabDelivery Note` |
| 25 | set |
| 26 | per_billed = (select sum(if(qty > ifnull(billed_qty, 0), billed_qty, qty))/sum(qty)*100 from `tabDelivery Note Detail` where parent='%s') |
| 27 | where |
| 28 | name='%s'""" % (d[0], d[0])) |
| 29 | |
| 30 | |
| 31 | # update delivery/billing status |
| 32 | #------------------------------- |
| 33 | def update_status(): |
| 34 | sql("""update `tabSales Order` set delivery_status = if(ifnull(per_delivered,0) < 0.001, 'Not Delivered', |
| 35 | if(per_delivered >= 99.99, 'Fully Delivered', 'Partly Delivered'))""") |
| 36 | sql("""update `tabSales Order` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed', |
| 37 | if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""") |
| 38 | sql("""update `tabDelivery Note` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed', |
| 39 | if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""") |
| 40 | |
| 41 | def run_patch(): |
| 42 | update_percent() |
| 43 | update_status() |