Add indexes in some transaction doctypes (#9889)

diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.py b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.py
index 03f1bc5..b711e36 100644
--- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.py
+++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.py
@@ -11,3 +11,6 @@
 class PurchaseOrderItem(Document):
 	def __setup__(self):
 		print_settings_for_item_table(self)
+
+def on_doctype_update():
+	frappe.db.add_index("Purchase Order Item", ["item_code", "warehouse"])
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/production_order_item/production_order_item.py b/erpnext/manufacturing/doctype/production_order_item/production_order_item.py
index c18338c..e52ccc2 100644
--- a/erpnext/manufacturing/doctype/production_order_item/production_order_item.py
+++ b/erpnext/manufacturing/doctype/production_order_item/production_order_item.py
@@ -8,3 +8,6 @@
 
 class ProductionOrderItem(Document):
 	pass
+
+def on_doctype_update():
+	frappe.db.add_index("Production Order Item", ["item_code", "source_warehouse"])
\ No newline at end of file
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index fd985d0..f8267df 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -416,4 +416,5 @@
 erpnext.patches.v8_1.remove_sales_invoice_from_returned_serial_no
 erpnext.patches.v8_1.allow_invoice_copy_to_edit_after_submit
 erpnext.patches.v8_1.add_hsn_sac_codes
-erpnext.patches.v8_1.update_gst_state
\ No newline at end of file
+erpnext.patches.v8_1.update_gst_state
+erpnext.patches.v8_1.add_indexes_in_transaction_doctypes
\ No newline at end of file
diff --git a/erpnext/patches/v8_1/add_indexes_in_transaction_doctypes.py b/erpnext/patches/v8_1/add_indexes_in_transaction_doctypes.py
new file mode 100644
index 0000000..21a47fb
--- /dev/null
+++ b/erpnext/patches/v8_1/add_indexes_in_transaction_doctypes.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+import frappe
+
+def execute():
+	for dt in ("Sales Order Item", "Purchase Order Item",
+		"Material Request Item", "Production Order Item", "Packed Item"):
+			frappe.get_doc("DocType", dt).run_module_method("on_doctype_update")
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.py b/erpnext/selling/doctype/sales_order_item/sales_order_item.py
index 94ac823..4a87a0c 100644
--- a/erpnext/selling/doctype/sales_order_item/sales_order_item.py
+++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.py
@@ -10,3 +10,6 @@
 class SalesOrderItem(Document):
 	def __setup__(self):
 		print_settings_for_item_table(self)
+
+def on_doctype_update():
+	frappe.db.add_index("Sales Order Item", ["item_code", "warehouse"])
\ No newline at end of file
diff --git a/erpnext/stock/doctype/material_request_item/material_request_item.py b/erpnext/stock/doctype/material_request_item/material_request_item.py
index b365217..16f007f 100644
--- a/erpnext/stock/doctype/material_request_item/material_request_item.py
+++ b/erpnext/stock/doctype/material_request_item/material_request_item.py
@@ -9,4 +9,7 @@
 from frappe.model.document import Document
 
 class MaterialRequestItem(Document):
-	pass
\ No newline at end of file
+	pass
+
+def on_doctype_update():
+	frappe.db.add_index("Material Request Item", ["item_code", "warehouse"])
\ No newline at end of file
diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py
index 582960d..d6db40d 100644
--- a/erpnext/stock/doctype/packed_item/packed_item.py
+++ b/erpnext/stock/doctype/packed_item/packed_item.py
@@ -103,4 +103,7 @@
 		})
 		items.append(get_item_details(args))
 		
-	return items
\ No newline at end of file
+	return items
+	
+def on_doctype_update():
+	frappe.db.add_index("Packed Item", ["item_code", "warehouse"])
\ No newline at end of file