hide display of from/to warehouse based on purpose
diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js
index e48bb11..8e58e9a 100644
--- a/stock/doctype/stock_entry/stock_entry.js
+++ b/stock/doctype/stock_entry/stock_entry.js
@@ -28,7 +28,7 @@
 	
 	refresh: function() {
 		this._super();
-		this.toggle_related_fields(doc);
+		this.toggle_related_fields(this.frm.doc);
 		if (this.frm.doc.docstatus==1) this.frm.add_custom_button("Show Stock Ledger", 
 			this.show_stock_ledger)
 	},
@@ -54,6 +54,15 @@
 cur_frm.cscript = new erpnext.stock.StockEntry({frm: cur_frm});
 
 cur_frm.cscript.toggle_related_fields = function(doc) {
+	disable_from_warehouse = inList(["Material Receipt", "Sales Return"], doc.purpose);
+	disable_to_warehouse = inList(["Material Issue", "Purchase Return"], doc.purpose)
+	
+	cur_frm.toggle_enable("from_warehouse", !disable_from_warehouse);
+	cur_frm.toggle_enable("to_warehouse", !disable_to_warehouse);
+		
+	cur_frm.fields_dict["mtn_details"].grid.set_column_disp("s_warehouse", !disable_from_warehouse);
+	cur_frm.fields_dict["mtn_details"].grid.set_column_disp("t_warehouse", !disable_to_warehouse);
+	
 	if(doc.purpose == 'Purchase Return') {
 		doc.customer = doc.customer_name = doc.customer_address = 
 			doc.delivery_note_no = doc.sales_invoice_no = null;
diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py
index 72def4b..7f2a23e 100644
--- a/stock/doctype/stock_entry/stock_entry.py
+++ b/stock/doctype/stock_entry/stock_entry.py
@@ -80,9 +80,6 @@
 			if not (d.s_warehouse or d.t_warehouse):
 				msgprint(_("Atleast one warehouse is mandatory"), raise_exception=1)
 			
-			if d.s_warehouse == d.t_warehouse:
-				msgprint(_("Source and Target Warehouse cannot be same"), raise_exception=1)
-				
 			if self.doc.purpose in source_mandatory:
 				if not d.s_warehouse:
 					msgprint(_("Row # ") + "%s: " % cint(d.idx)
@@ -117,6 +114,11 @@
 					if not d.s_warehouse:
 						msgprint(_("Row # ") + "%s: " % cint(d.idx)
 							+ _("Source Warehouse") + _(" is mandatory"), raise_exception=1)
+							
+			if d.s_warehouse == d.t_warehouse:
+				msgprint(_("Source and Target Warehouse cannot be same"), raise_exception=1)
+				
+
 				
 	def validate_production_order(self, pro_obj=None):
 		if not pro_obj: