From c3daa91c8a0fe56ecbd3508970008fbc5aac9c1d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 16 Apr 2015 13:13:18 +0530 Subject: [PATCH] Reset no-copy fields for recurring docs and patch to fix --- .../doctype/purchase_order/purchase_order.py | 11 +++++ erpnext/patches.txt | 3 +- erpnext/patches/v4_2/fix_recurring_orders.py | 41 +++++++++++++++++++ .../doctype/sales_order/sales_order.py | 11 +++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v4_2/fix_recurring_orders.py diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index 09f303f6aa..6a06d24b46 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -198,6 +198,17 @@ class PurchaseOrder(BuyingController): def on_update(self): pass + def before_recurring(self): + super(PurchaseOrder, self).before_recurring() + + for field in ("per_received", "per_billed"): + self.set(field, None) + + for d in self.get("po_details"): + for field in ("received_qty", "billed_amt", "prevdoc_doctype", "prevdoc_docname", + "prevdoc_detail_docname", "supplier_quotation", "supplier_quotation_item"): + d.set(field, None) + def set_missing_values(source, target): target.ignore_pricing_rule = 1 target.run_method("set_missing_values") diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e3437a56f5..6e84b7bb6d 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -95,4 +95,5 @@ erpnext.patches.v4_2.update_landed_cost_voucher erpnext.patches.v4_2.set_item_has_batch erpnext.patches.v4_2.update_stock_uom_for_dn_in_sle erpnext.patches.v4_2.repost_reserved_qty -erpnext.patches.v4_2.repost_sle_for_si_with_no_warehouse \ No newline at end of file +erpnext.patches.v4_2.repost_sle_for_si_with_no_warehouse +erpnext.patches.v4_2.fix_recurring_orders \ No newline at end of file diff --git a/erpnext/patches/v4_2/fix_recurring_orders.py b/erpnext/patches/v4_2/fix_recurring_orders.py new file mode 100644 index 0000000000..ea1724a040 --- /dev/null +++ b/erpnext/patches/v4_2/fix_recurring_orders.py @@ -0,0 +1,41 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + sales_orders = frappe.db.sql("""select name from `tabSales Order` + where docstatus = 1 and ifnull(is_recurring, 0) = 1 + and (per_delivered > 0 or per_billed > 0)""", as_dict=1) + + for so in sales_orders: + if not frappe.db.exists("Delivery Note Item", {"against_sales_order": so.name, "docstatus": 1}): + frappe.db.sql("""update `tabSales Order` set per_delivered = 0, + delivery_status = 'Not Delivered' where name = %s""", so.name) + frappe.db.sql("""update `tabSales Order Item` set delivered_qty = 0 + where parent = %s""", so.name) + + if not frappe.db.exists("Sales Invoice Item", {"sales_order": so.name, "docstatus": 1}): + frappe.db.sql("""update `tabSales Order` set per_billed = 0, + billing_status = 'Not Billed' where name = %s""", so.name) + frappe.db.sql("""update `tabSales Order Item` set billed_amt = 0 + where parent = %s""", so.name) + + purchase_orders = frappe.db.sql("""select name from `tabPurchase Order` + where docstatus = 1 and ifnull(is_recurring, 0) = 1 + and (per_received > 0 or per_billed > 0)""", as_dict=1) + + for po in purchase_orders: + if not frappe.db.exists("Purchase Receipt Item", {"prevdoc_doctype": "Purchase Order", + "prevdoc_docname": po.name, "docstatus": 1}): + frappe.db.sql("""update `tabPurchase Order` set per_received = 0 + where name = %s""", po.name) + frappe.db.sql("""update `tabPurchase Order Item` set received_qty = 0 + where parent = %s""", po.name) + + if not frappe.db.exists("Purchase Invoice Item", {"purchase_order": po.name, "docstatus": 1}): + frappe.db.sql("""update `tabPurchase Order` set per_billed = 0 + where name = %s""", po.name) + frappe.db.sql("""update `tabPurchase Order Item` set billed_amt = 0 + where parent = %s""", po.name) \ No newline at end of file diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 5b0f7e9708..040b999afb 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -249,6 +249,17 @@ class SalesOrder(SellingController): def get_portal_page(self): return "order" if self.docstatus==1 else None + def before_recurring(self): + super(SalesOrder, self).before_recurring() + + for field in ("delivery_status", "per_delivered", "billing_status", "per_billed"): + self.set(field, None) + + for d in self.get("sales_order_details"): + for field in ("delivered_qty", "billed_amt", "planned_qty", "prevdoc_docname"): + d.set(field, None) + + @frappe.whitelist() def make_material_request(source_name, target_doc=None): def postprocess(source, doc):