Merge pull request #19477 from rohitwaghchaure/production_plan_warehouse_not_changed

fix: Wrong warehouse fetched in production plan
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 2f6b59f..a9e50ba 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -152,6 +152,20 @@
 def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
 	conditions = []
 
+	#Get searchfields from meta and use in Item Link field query
+	meta = frappe.get_meta("Item", cached=True)
+	searchfields = meta.get_search_fields()
+
+	if "description" in searchfields:
+		searchfields.remove("description")
+
+	columns = [field for field in searchfields if not field in ["name", "item_group", "description"]]
+	columns = ", ".join(columns)
+
+	searchfields = searchfields + [field for field in[searchfield or "name", "item_code", "item_group", "item_name"]
+		if not field in searchfields]
+	searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])
+
 	description_cond = ''
 	if frappe.db.count('Item', cache=True) < 50000:
 		# scan description only if items are less than 50000
@@ -162,17 +176,14 @@
 			concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
 		tabItem.item_group,
 		if(length(tabItem.description) > 40, \
-			concat(substr(tabItem.description, 1, 40), "..."), description) as decription
+			concat(substr(tabItem.description, 1, 40), "..."), description) as description,
+		{columns}
 		from tabItem
 		where tabItem.docstatus < 2
 			and tabItem.has_variants=0
 			and tabItem.disabled=0
 			and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
-			and (tabItem.`{key}` LIKE %(txt)s
-				or tabItem.item_code LIKE %(txt)s
-				or tabItem.item_group LIKE %(txt)s
-				or tabItem.item_name LIKE %(txt)s
-				or tabItem.item_code IN (select parent from `tabItem Barcode` where barcode LIKE %(txt)s)
+			and ({scond} or tabItem.item_code IN (select parent from `tabItem Barcode` where barcode LIKE %(txt)s)
 				{description_cond})
 			{fcond} {mcond}
 		order by
@@ -182,6 +193,8 @@
 			name, item_name
 		limit %(start)s, %(page_len)s """.format(
 			key=searchfield,
+			columns=columns,
+			scond=searchfields,
 			fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
 			mcond=get_match_cond(doctype).replace('%', '%%'),
 			description_cond = description_cond),
diff --git a/erpnext/stock/doctype/serial_no/serial_no_list.js b/erpnext/stock/doctype/serial_no/serial_no_list.js
new file mode 100644
index 0000000..5b1e312
--- /dev/null
+++ b/erpnext/stock/doctype/serial_no/serial_no_list.js
@@ -0,0 +1,14 @@
+frappe.listview_settings['Serial No'] = {
+	add_fields: ["is_cancelled", "item_code", "warehouse", "warranty_expiry_date", "delivery_document_type"],
+	get_indicator: (doc) => {
+		if (doc.is_cancelled) {
+			return [__("Cancelled"), "red", "is_cancelled,=,Yes"];
+		} else if (doc.delivery_document_type) {
+			return [__("Delivered"), "green", "delivery_document_type,is,set|is_cancelled,=,No"];
+		} else if (doc.warranty_expiry_date && frappe.datetime.get_diff(doc.warranty_expiry_date, frappe.datetime.nowdate()) <= 0) {
+			return [__("Expired"), "red", "warranty_expiry_date,not in,|warranty_expiry_date,<=,Today|delivery_document_type,is,not set|is_cancelled,=,No"];
+		} else {
+			return [__("Active"), "green", "delivery_document_type,is,not set|is_cancelled,=,No"];
+		}
+	}
+};