From 4b9d2f27336caffab98966b333a268dee408dcba Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 16 Feb 2017 15:53:40 +0530 Subject: [PATCH] [Fix] Cleanup supplied items if supply raw material is set as No --- erpnext/controllers/buying_controller.py | 3 +++ erpnext/patches.txt | 3 ++- .../empty_supplied_items_for_non_subcontracted.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v7_2/empty_supplied_items_for_non_subcontracted.py diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index c4ba9e7b1d..1d1b4e2198 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -178,6 +178,9 @@ class BuyingController(StockController): for item in self.get("items"): item.rm_supp_cost = 0.0 + if self.is_subcontracted == "No" and self.get("supplied_items"): + self.set('supplied_items', []) + def update_raw_materials_supplied(self, item, raw_material_table): bom_items = self.get_items_from_bom(item.item_code, item.bom) raw_materials_cost = 0 diff --git a/erpnext/patches.txt b/erpnext/patches.txt index b997dfc13b..6563dfb3ee 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -363,4 +363,5 @@ erpnext.patches.v7_2.update_website_for_variant erpnext.patches.v7_2.update_doctype_status erpnext.patches.v7_2.update_salary_slips erpnext.patches.v7_2.set_null_value_to_fields -erpnext.patches.v7_2.update_abbr_in_salary_slips \ No newline at end of file +erpnext.patches.v7_2.update_abbr_in_salary_slips +erpnext.patches.v7_2.empty_supplied_items_for_non_subcontracted \ No newline at end of file diff --git a/erpnext/patches/v7_2/empty_supplied_items_for_non_subcontracted.py b/erpnext/patches/v7_2/empty_supplied_items_for_non_subcontracted.py new file mode 100644 index 0000000000..ec6f8afc3a --- /dev/null +++ b/erpnext/patches/v7_2/empty_supplied_items_for_non_subcontracted.py @@ -0,0 +1,14 @@ +# 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(): + for doctype in ["Purchase Order", "Purchase Invoice", "Purchase Receipt"]: + child_table = 'Purchase Receipt Item Supplied' if doctype != 'Purchase Order' else 'Purchase Order Item Supplied' + for data in frappe.db.sql(""" select distinct `tab{doctype}`.name from `tab{doctype}` , `tab{child_table}` + where `tab{doctype}`.name = `tab{child_table}`.parent and `tab{doctype}`.docstatus != 2 + and `tab{doctype}`.is_subcontracted = 'No' """.format(doctype = doctype, child_table = child_table), as_dict=1): + frappe.db.sql(""" delete from `tab{child_table}` + where parent = %s and parenttype = %s""".format(child_table= child_table), (data.name, doctype)) \ No newline at end of file