From e06526ffff48b9123f9e3caca25f11aa6e132d3d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 17 Jul 2017 13:28:27 +0530 Subject: [PATCH] Add indexes in some transaction doctypes (#9889) --- .../doctype/purchase_order_item/purchase_order_item.py | 3 +++ .../production_order_item/production_order_item.py | 3 +++ erpnext/patches.txt | 3 ++- .../patches/v8_1/add_indexes_in_transaction_doctypes.py | 9 +++++++++ .../selling/doctype/sales_order_item/sales_order_item.py | 3 +++ .../material_request_item/material_request_item.py | 5 ++++- erpnext/stock/doctype/packed_item/packed_item.py | 5 ++++- 7 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 erpnext/patches/v8_1/add_indexes_in_transaction_doctypes.py 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 03f1bc5360..b711e36bf9 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 @@ from erpnext.controllers.print_settings import print_settings_for_item_table 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 c18338ceb8..e52ccc2e0f 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 @@ from frappe.model.document import Document 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 fd985d0f4d..f8267df631 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -416,4 +416,5 @@ erpnext.patches.v8_0.update_production_orders 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 0000000000..21a47fbc60 --- /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 94ac823261..4a87a0c28a 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 @@ from erpnext.controllers.print_settings import print_settings_for_item_table 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 b365217ed4..16f007f6a2 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 @@ import frappe 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 582960de4d..d6db40d202 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.py +++ b/erpnext/stock/doctype/packed_item/packed_item.py @@ -103,4 +103,7 @@ def get_items_from_product_bundle(args): }) 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