test: check index creation on item table
diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py
index 2366f06..d9d1e5a 100644
--- a/erpnext/stock/doctype/item/test_item.py
+++ b/erpnext/stock/doctype/item/test_item.py
@@ -487,6 +487,20 @@
new_barcode.barcode_type = 'EAN'
self.assertRaises(InvalidBarcode, item_doc.save)
+ def test_index_creation(self):
+ "check if index is getting created in db"
+ from erpnext.stock.doctype.item.item import on_doctype_update
+ on_doctype_update()
+
+ indices = frappe.db.sql("show index from tabItem", as_dict=1)
+ expected_columns = {"item_code", "item_name", "item_group", "route"}
+ for index in indices:
+ expected_columns.discard(index.get("Column_name"))
+
+ if expected_columns:
+ self.fail(f"Expected db index on these columns: {', '.join(expected_columns)}")
+
+
def set_item_variant_settings(fields):
doc = frappe.get_doc('Item Variant Settings')
doc.set('fields', fields)