[minor] Show item quantity in warehouse set query
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index cc3f277..be0cb02 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -348,3 +348,30 @@
 			'company': filters.get("company", ""),
 			'txt': "%%%s%%" % frappe.db.escape(txt)
 		})
+
+
+@frappe.whitelist()
+def warehouse_query(doctype, txt, searchfield, start, page_len, filters):
+	# Should be used when item code is passed in filters.
+	conditions = []
+	response = frappe.db.sql("""select distinct `tabWarehouse`.name,
+			CONCAT_WS(" : ", "Actual Qty", ifnull(round(`tabBin`.actual_qty, 2), 0))
+			from `tabWarehouse` INNER JOIN `tabBin`
+			on `tabWarehouse`.name = `tabBin`.warehouse
+			where
+			   `tabWarehouse`.`{key}` like %(txt)s
+				{fcond} {mcond}
+			order by
+				`tabWarehouse`.name, `tabBin`.actual_qty desc
+			limit
+				%(start)s, %(page_len)s """.format(
+					key=frappe.db.escape(searchfield),
+					fcond=get_filters_cond(doctype, filters, conditions),
+					mcond=get_match_cond(doctype)
+				),
+				{
+					"txt": "%%%s%%" % frappe.db.escape(txt),
+					"start": start,
+					"page_len": page_len,
+				})
+	return response
diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js
index f3167bb..bf7143a 100644
--- a/erpnext/public/js/queries.js
+++ b/erpnext/public/js/queries.js
@@ -133,3 +133,19 @@
 			set_query(df.options, df.fieldname);
 		});
 }
+
+/* 	if item code is selected in child table
+	then list down warehouses with its quantity
+	else apply default filters.
+*/
+erpnext.queries.setup_warehouse_query = function(frm){
+	frm.set_query('warehouse', 'items', function(doc, cdt, cdn) {
+		var row  = locals[cdt][cdn];
+		var filters = erpnext.queries.warehouse(frm.doc);
+		if(row.item_code){
+			$.extend(filters, {"query":"erpnext.controllers.queries.warehouse_query"});
+			filters["filters"].push(["Bin", "item_code", "=", row.item_code]);
+		}
+		return filters
+	});
+}
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index f01e484..8130ce8 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -24,6 +24,8 @@
 		// formatter for material request item
 		frm.set_indicator_formatter('item_code',
 			function(doc) { return (doc.qty<=doc.delivered_qty) ? "green" : "orange" })
+
+		erpnext.queries.setup_warehouse_query(frm);
 	}
 });
 
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 8f87198..23806d4 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -13,14 +13,7 @@
 				return (doc.docstatus==1 || doc.qty<=doc.actual_qty) ? "green" : "orange"
 			})
 
-		frm.set_query("warehouse", "items", function() {
-			return {
-				filters: [
-					["Warehouse", "company", "in", ["", cstr(frm.doc.company)]],
-					["Warehouse", "is_group", "=", 0]
-				]
-			}
-		})
+		erpnext.queries.setup_warehouse_query(frm);
 
 	}
 });
diff --git a/erpnext/stock/doctype/warehouse/warehouse.json b/erpnext/stock/doctype/warehouse/warehouse.json
index 477041f..913d133 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.json
+++ b/erpnext/stock/doctype/warehouse/warehouse.json
@@ -655,7 +655,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:06:39.128312", 
+ "modified": "2017-01-12 16:08:01.207466", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Warehouse", 
@@ -791,7 +791,9 @@
  "quick_entry": 1, 
  "read_only": 0, 
  "read_only_onload": 0, 
+ "search_fields": "", 
  "sort_order": "DESC", 
  "title_field": "warehouse_name", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file