added warehouse user to retrict entry and also introduced query handlers
diff --git a/home/page/latest_updates/latest_updates.js b/home/page/latest_updates/latest_updates.js
index d1561e0..db64849 100644
--- a/home/page/latest_updates/latest_updates.js
+++ b/home/page/latest_updates/latest_updates.js
@@ -1,4 +1,7 @@
 erpnext.updates = [
+	["2nd February, 2013", [
+		"Warehouse: Added table Warehouse User to restrict Warehouse Entry per user.",
+	]],
 	["28st January, 2013", [
 		"List Views are now configurable: To set list views, check 'In List View' in Setup > Customize Form View in the fields table.",
 	]],
diff --git a/startup/query_handlers.py b/startup/query_handlers.py
new file mode 100644
index 0000000..5e28608
--- /dev/null
+++ b/startup/query_handlers.py
@@ -0,0 +1,5 @@
+from __future__ import unicode_literals
+
+standard_queries = {
+	"Warehouse": "stock.utils.get_warehouse_list"
+}
\ No newline at end of file
diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 2b1af33..d1fe3d9 100644
--- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -16,6 +16,7 @@
 
 from __future__ import unicode_literals
 import webnotes
+from webnotes import _
 
 from webnotes.utils import cint, flt, getdate
 
@@ -33,6 +34,7 @@
 	def validate(self):
 		self.validate_mandatory()
 		self.validate_item()
+		self.validate_warehouse_user()
 		self.actual_amt_check()
 		self.check_stock_frozen_date()
 		self.scrub_posting_time()
@@ -51,6 +53,15 @@
 
 			self.doc.fields.pop('batch_bal')
 			 
+	def validate_warehouse_user(self):
+		if webnotes.session.user=="Administrator":
+			return
+		warehouse_users = [p[0] for p in webnotes.conn.sql("""select user from `tabWarehouse User`
+			where parent=%s""", self.doc.warehouse)]
+			
+		if warehouse_users and not webnotes.session.user in warehouse_users:
+			webnotes.msgprint(_("User not allowed entry in the Warehouse") \
+				+ ": " + webnotes.session.user + " / " + self.doc.warehouse, raise_exception = 1)
 
 	def validate_mandatory(self):		
 		mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company']
diff --git a/stock/doctype/warehouse/warehouse.txt b/stock/doctype/warehouse/warehouse.txt
index e767543..d0dd73c 100644
--- a/stock/doctype/warehouse/warehouse.txt
+++ b/stock/doctype/warehouse/warehouse.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-10 16:34:30", 
   "docstatus": 0, 
-  "modified": "2013-01-29 13:29:21", 
+  "modified": "2013-02-04 11:35:53", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -81,6 +81,21 @@
   "search_index": 1
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "column_break_4", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "If set, data entry is only allowed for specified users. Else, entry is allowed for all users with requisite permissions.", 
+  "doctype": "DocField", 
+  "fieldname": "warehouse_users", 
+  "fieldtype": "Table", 
+  "label": "Warehouse Users", 
+  "options": "Warehouse User", 
+  "permlevel": 0
+ }, 
+ {
   "description": "For Reference Only.", 
   "doctype": "DocField", 
   "fieldname": "warehouse_contact_info", 
diff --git a/stock/doctype/warehouse_user/__init__.py b/stock/doctype/warehouse_user/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/stock/doctype/warehouse_user/__init__.py
diff --git a/stock/doctype/warehouse_user/warehouse_user.py b/stock/doctype/warehouse_user/warehouse_user.py
new file mode 100644
index 0000000..928aa9f
--- /dev/null
+++ b/stock/doctype/warehouse_user/warehouse_user.py
@@ -0,0 +1,8 @@
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+class DocType:
+	def __init__(self, d, dl):
+		self.doc, self.doclist = d, dl
\ No newline at end of file
diff --git a/stock/doctype/warehouse_user/warehouse_user.txt b/stock/doctype/warehouse_user/warehouse_user.txt
new file mode 100644
index 0000000..6cb02ae
--- /dev/null
+++ b/stock/doctype/warehouse_user/warehouse_user.txt
@@ -0,0 +1,36 @@
+[
+ {
+  "creation": "2013-02-04 11:33:57", 
+  "docstatus": 0, 
+  "modified": "2013-02-04 11:36:16", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "doctype": "DocType", 
+  "document_type": "Other", 
+  "istable": 1, 
+  "module": "Stock", 
+  "name": "__common__"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "user", 
+  "fieldtype": "Link", 
+  "label": "User", 
+  "name": "__common__", 
+  "options": "Profile", 
+  "parent": "Warehouse User", 
+  "parentfield": "fields", 
+  "parenttype": "DocType", 
+  "permlevel": 0, 
+  "width": "200px"
+ }, 
+ {
+  "doctype": "DocType", 
+  "name": "Warehouse User"
+ }, 
+ {
+  "doctype": "DocField"
+ }
+]
\ No newline at end of file
diff --git a/stock/utils.py b/stock/utils.py
index 46dd9d0..87f4c02 100644
--- a/stock/utils.py
+++ b/stock/utils.py
@@ -146,4 +146,21 @@
 			+ cstr(abs(qty)) + " quantity against item code: " + item_code,
 			raise_exception=1)
 		
-	return valid_serial_nos
\ No newline at end of file
+	return valid_serial_nos
+	
+def get_warehouse_list(doctype, txt, searchfield, start, page_len):
+	"""used in search queries"""
+	wlist = []
+	for w in webnotes.conn.sql_list("""select name from tabWarehouse 
+		where name like '%%%s%%'""" % txt):
+		if webnotes.session.user=="Administrator":
+			wlist.append([w])
+		else:
+			warehouse_users = webnotes.conn.sql_list("""select user from `tabWarehouse User` 
+				where parent=%s""", w)
+			if not warehouse_users:
+				wlist.append([w])
+			elif webnotes.session.user in warehouse_users:
+				wlist.append([w])
+	return wlist
+	
\ No newline at end of file