fixed delivery/billing status issue and patched for old records

This commit is contained in:
nabinhait
2011-06-28 14:42:07 +05:30
parent e9f158f196
commit 690c697fab
3 changed files with 57 additions and 30 deletions

View File

@@ -0,0 +1,43 @@
import webnotes
sql = webnotes.conn.sql
# update SO
#---------------
def update_percent():
so = sql("select name from `tabSales Order` where docstatus = 1")
for d in so:
sql("""
update
`tabSales Order`
set
per_delivered = (select sum(if(qty > ifnull(delivered_qty, 0), delivered_qty, qty))/sum(qty)*100 from `tabSales Order Detail` where parent='%s'),
per_billed = (select sum(if(qty > ifnull(billed_qty, 0), billed_qty, qty))/sum(qty)*100 from `tabSales Order Detail` where parent='%s')
where
name='%s'""" % (d[0], d[0], d[0]))
# update DN
# ---------
dn = sql("select name from `tabDelivery Note` where docstatus = 1")
for d in dn:
sql("""
update
`tabDelivery Note`
set
per_billed = (select sum(if(qty > ifnull(billed_qty, 0), billed_qty, qty))/sum(qty)*100 from `tabDelivery Note Detail` where parent='%s')
where
name='%s'""" % (d[0], d[0]))
# update delivery/billing status
#-------------------------------
def update_status():
sql("""update `tabSales Order` set delivery_status = if(ifnull(per_delivered,0) < 0.001, 'Not Delivered',
if(per_delivered >= 99.99, 'Fully Delivered', 'Partly Delivered'))""")
sql("""update `tabSales Order` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed',
if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
sql("""update `tabDelivery Note` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed',
if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
def run_patch():
update_percent()
update_status()

View File

@@ -1,6 +1,6 @@
# REMEMBER to update this
# ========================
last_patch = 299
last_patch = 300
#-------------------------------------------
@@ -1192,3 +1192,6 @@ def execute(patch_no):
sql("update `tabDocField` set options = 'Link:Company' where parent = 'Appraisal' and fieldname = 'company'")
elif patch_no == 299:
sql("update `tabDocPerm` set `match` = NULL where parent = 'Employee' and role = 'Employee'")
elif patch_no == 300:
from patches.delivery_billing_status_patch import run_patch
run_patch()