delievery billing status patch

This commit is contained in:
Nabin Hait 2011-09-14 11:40:01 +05:30
parent 67127150ae
commit f2718d1064
2 changed files with 38 additions and 23 deletions

View File

@ -1,32 +1,43 @@
import webnotes import webnotes
sql = webnotes.conn.sql sql = webnotes.conn.sql
test=1
# Update SO and DN Detail
#--------------------------
def update_delivered_billed_qty():
# update billed amt in item table in so and dn
sql(""" update `tabSales Order Detail` so
set billed_amt = (select sum(amount) from `tabRV Detail` where `so_detail`= so.name and docstatus=1 and parent not like 'old%%'),
delivered_qty = (select sum(qty) from `tabDelivery Note Detail` where `prevdoc_detail_docname`= so.name and docstatus=1 and parent not like 'old%%'),
modified = now()
where docstatus = 1
""")
sql(""" update `tabDelivery Note Detail` dn
set billed_amt = (select sum(amount) from `tabRV Detail` where `dn_detail`= dn.name and docstatus=1 and parent not like 'old%%'),
modified = now()
where docstatus = 1
""")
# update SO # update SO
#--------------- #---------------
def update_percent(): def update_percent():
so = sql("select name from `tabSales Order` where docstatus = 1") # calculate % billed based on item table
for d in so: sql(""" update `tabSales Order` so
sql(""" set per_delivered = (select sum(if(qty > ifnull(delivered_qty, 0), delivered_qty, qty))/sum(qty)*100 from `tabSales Order Detail` where parent=so.name),
update per_billed = (select sum(if(amount > ifnull(billed_amt, 0), billed_amt, amount))/sum(amount)*100 from `tabSales Order Detail` where parent = so.name),
`tabSales Order` modified = now()
set where docstatus = 1
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 # update DN
# --------- # ---------
dn = sql("select name from `tabDelivery Note` where docstatus = 1") sql(""" update `tabDelivery Note` dn
for d in dn: set per_billed = (select sum(if(amount > ifnull(billed_amt, 0), billed_amt, amount))/sum(amount)*100 from `tabDelivery Note Detail` where parent = dn.name),
sql(""" modified = now()
update where docstatus=1
`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 # update delivery/billing status
#------------------------------- #-------------------------------
@ -39,5 +50,6 @@ def update_status():
if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""") if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
def run_patch(): def run_patch():
update_delivered_billed_qty()
update_percent() update_percent()
update_status() update_status()

View File

@ -1,7 +1,7 @@
# REMEMBER to update this # REMEMBER to update this
# ======================== # ========================
last_patch = 364 last_patch = 365
#------------------------------------------- #-------------------------------------------
@ -337,3 +337,6 @@ def execute(patch_no):
for d in mappers: for d in mappers:
if d[0] and d[1]: if d[0] and d[1]:
reload_doc(d[1].lower(), 'DocType Mapper', d[0]) reload_doc(d[1].lower(), 'DocType Mapper', d[0])
elif patch_no == 365:
from patches.delivery_billing_status_patch import run_patch
run_patch()