[patch] Set default material request type in Item based on default bom
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 4d3932f..4e99afa 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -307,4 +307,4 @@
erpnext.patches.v7_0.remove_old_earning_deduction_doctypes
erpnext.patches.v7_0.make_guardian
erpnext.patches.v7_0.update_refdoc_in_landed_cost_voucher
-execute:frappe.db.sql("update `tabItem` set default_material_request_type= case when default_bom is not null then 'Manufacture' else 'Purchase' end")
+erpnext.patches.v7_0.set_material_request_type_in_item
\ No newline at end of file
diff --git a/erpnext/patches/v7_0/set_material_request_type_in_item.py b/erpnext/patches/v7_0/set_material_request_type_in_item.py
new file mode 100644
index 0000000..5fb14ad
--- /dev/null
+++ b/erpnext/patches/v7_0/set_material_request_type_in_item.py
@@ -0,0 +1,16 @@
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+ frappe.reload_doctype("Item")
+ if "default_bom" in frappe.db.get_table_columns("Item"):
+ frappe.db.sql("""update `tabItem`
+ set default_material_request_type = (
+ case
+ when (default_bom is not null and default_bom != '')
+ then 'Manufacture'
+ else 'Purchase'
+ end )""")
+
+ else:
+ frappe.db.sql("update tabItem set default_material_request_type='Purchase'")
\ No newline at end of file