Merge pull request #7764 from rohitwaghchaure/clean_supplied_items

[Fix] Cleanup supplied items if supply raw material is set as No
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index c4ba9e7..1d1b4e2 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -178,6 +178,9 @@
 			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 b997dfc..6563dfb 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -363,4 +363,5 @@
 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 0000000..ec6f8af
--- /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