From 8c56adf42b34e6ea6529aa263c9988f764b5b32a Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 20 Nov 2015 00:41:05 +0530 Subject: [PATCH] [hotfix] drop ship patch --- .../v6_8/move_drop_ship_to_po_items.py | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/erpnext/patches/v6_8/move_drop_ship_to_po_items.py b/erpnext/patches/v6_8/move_drop_ship_to_po_items.py index c935831bc9..1c2a57a93b 100644 --- a/erpnext/patches/v6_8/move_drop_ship_to_po_items.py +++ b/erpnext/patches/v6_8/move_drop_ship_to_po_items.py @@ -1,37 +1,39 @@ import frappe def execute(): + frappe.reload_doctype("Purchase Order") frappe.reload_doctype("Purchase Order Item") + for po in frappe.get_all("Purchase Order", filters={"delivered_by_supplier": 1}, fields=["name"]): purchase_order = frappe.get_doc("Purchase Order", po) - + for item in purchase_order.items: if item.prevdoc_doctype == "Sales Order": - delivered_by_supplier = frappe.get_value("Sales Order Item", item.prevdoc_detail_docname, + delivered_by_supplier = frappe.get_value("Sales Order Item", item.prevdoc_detail_docname, "delivered_by_supplier") - + if delivered_by_supplier: - frappe.db.sql("""update `tabPurchase Order Item` + frappe.db.sql("""update `tabPurchase Order Item` set delivered_by_supplier=1, billed_amt=amount, received_qty=qty where name=%s """, item.name) - + update_per_received(purchase_order) update_per_billed(purchase_order) - + def update_per_received(po): - frappe.db.sql(""" update `tabPurchase Order` - set per_received = round((select sum(if(qty > ifnull(received_qty, 0), - ifnull(received_qty, 0), qty)) / sum(qty) *100 - from `tabPurchase Order Item` - where parent = %(name)s), 2) + frappe.db.sql(""" update `tabPurchase Order` + set per_received = round((select sum(if(qty > ifnull(received_qty, 0), + ifnull(received_qty, 0), qty)) / sum(qty) *100 + from `tabPurchase Order Item` + where parent = %(name)s), 2) where name = %(name)s """, {"name": po.name}) def update_per_billed(po): - frappe.db.sql(""" update `tabPurchase Order` - set per_billed = round((select sum( if(amount > ifnull(billed_amt, 0), - ifnull(billed_amt, 0), amount)) / sum(amount) *100 - from `tabPurchase Order Item` - where parent = %(name)s), 2) + frappe.db.sql(""" update `tabPurchase Order` + set per_billed = round((select sum( if(amount > ifnull(billed_amt, 0), + ifnull(billed_amt, 0), amount)) / sum(amount) *100 + from `tabPurchase Order Item` + where parent = %(name)s), 2) where name = %(name)s """, {"name": po.name}) - +