Merge pull request #1966 from anandpdoshi/anand-july-21

Stock Entry Warehouse prefill, Item autosuggest by description
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.html b/erpnext/accounts/report/general_ledger/general_ledger.html
index 190d455..0fc02b1 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.html
+++ b/erpnext/accounts/report/general_ledger/general_ledger.html
@@ -27,7 +27,7 @@
 				<td>{%= data[i].voucher_type%}
 					<br>{%= data[i].voucher_no %}</td>
 				<td>{%= data[i].account %}
-					<br>{%= __("Against") %}: {%= data[i].account %}
+					<br>{%= __("Against") %}: {%= data[i].against_account %}
 					<br>{%= __("Remarks") %}: {%= data[i].remarks %}</td>
 				<td style="text-align: right">{%= format_currency(data[i].debit) %}</td>
 				<td style="text-align: right">{%= format_currency(data[i].credit) %}</td>
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 2650c66..4a30eed 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -167,7 +167,8 @@
 		where tabItem.docstatus < 2
 			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_name LIKE %(txt)s)
+				or tabItem.item_name LIKE %(txt)s
+				or tabItem.description LIKE %(txt)s)
 			{fcond} {mcond}
 		order by
 			if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 7274ece..dfcf07f 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -230,6 +230,36 @@
 		if(!row.t_warehouse) row.t_warehouse = this.frm.doc.to_warehouse;
 	},
 
+	source_mandatory: ["Material Issue", "Material Transfer", "Purchase Return"],
+	target_mandatory: ["Material Receipt", "Material Transfer", "Sales Return"],
+
+	from_warehouse: function(doc) {
+		var me = this;
+		this.set_warehouse_if_missing("s_warehouse", doc.from_warehouse, function(row) {
+			return me.source_mandatory.indexOf(me.frm.doc.purpose)!==-1;
+		});
+	},
+
+	to_warehouse: function(doc) {
+		var me = this;
+		this.set_warehouse_if_missing("t_warehouse", doc.to_warehouse, function(row) {
+			return me.target_mandatory.indexOf(me.frm.doc.purpose)!==-1;
+		});
+	},
+
+	set_warehouse_if_missing: function(fieldname, value, condition) {
+		for (var i=0, l=(this.frm.doc.mtn_details || []).length; i<l; i++) {
+			var row = this.frm.doc.mtn_details[i];
+			if (!row[fieldname]) {
+				if (condition && !condition(row)) {
+					continue;
+				}
+
+				frappe.model.set_value(row.doctype, row.name, fieldname, value, "Link");
+			}
+		}
+	},
+
 	mtn_details_on_form_rendered: function(doc, grid_row) {
 		erpnext.setup_serial_no(grid_row)
 	},