[Enhancement] Allow Multiple users in POS Profile
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json
index 187454e..a7c2c3d 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.json
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json
@@ -3,7 +3,7 @@
  "allow_guest_to_view": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
- "autoname": "hash", 
+ "autoname": "field:pos_profile_name", 
  "beta": 0, 
  "creation": "2013-05-24 12:15:51", 
  "custom": 0, 
@@ -17,6 +17,36 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "pos_profile_name", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "POS Profile Name", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "user", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -422,6 +452,67 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "section_break_15", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Applicable for Users", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "applicable_for_users", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Applicable for Users", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "POS Profile User", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_11", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1322,8 +1413,8 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-09-01 15:55:14.890452", 
- "modified_by": "Administrator", 
+ "modified": "2017-09-29 14:39:22.280700", 
+ "modified_by": "faris@erpnext.com", 
  "module": "Accounts", 
  "name": "POS Profile", 
  "owner": "Administrator", 
@@ -1375,7 +1466,7 @@
  "show_name_in_global_search": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
- "title_field": "user", 
+ "title_field": "pos_profile_name", 
  "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py
index 8d6a2db..3e37285 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.py
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py
@@ -11,7 +11,7 @@
 
 class POSProfile(Document):
 	def validate(self):
-		self.check_for_duplicate()
+		# self.check_for_duplicate()
 		self.validate_all_link_fields()
 		self.validate_duplicate_groups()
 		self.check_default_payment()
@@ -94,3 +94,44 @@
 @frappe.whitelist()
 def get_series():
 	return frappe.get_meta("Sales Invoice").get_field("naming_series").options or ""
+
+@frappe.whitelist()
+def get_pos_profiles_for_user(user=None):
+	out = []
+	if not user:
+		user = frappe.session.user
+
+	res = frappe.db.sql('''
+		select
+			parent
+		from
+			`tabPOS Profile User`
+		where
+			user = %s
+	''', (user), as_dict=1)
+
+	if not res:
+		company = frappe.defaults.get_user_default('company')
+		res = frappe.db.sql('''
+			select
+				pos_profile_name
+			from
+				`tabPOS Profile`
+			where
+				company = %s
+		''', (company), as_dict=1)
+
+		out = [r.pos_profile_name for r in res]
+
+		return out
+
+	for r in res:
+		name = frappe.db.get_value('POS Profile', r.parent, 'pos_profile_name')
+		out.append(name)
+
+	return out
+
+@frappe.whitelist()
+def get_pos_profile(pos_profile_name):
+	name = frappe.db.get_value('POS Profile', { 'pos_profile_name': pos_profile_name })
+	return frappe.get_doc('POS Profile', name)
diff --git a/erpnext/patches/v9_0/add_user_to_child_table_in_pos_profile.py b/erpnext/patches/v9_0/add_user_to_child_table_in_pos_profile.py
new file mode 100644
index 0000000..b2093c6
--- /dev/null
+++ b/erpnext/patches/v9_0/add_user_to_child_table_in_pos_profile.py
@@ -0,0 +1,21 @@
+# Copyright (c) 2017, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	doctype = 'POS Profile'
+	frappe.reload_doctype(doctype)
+
+	for doc in frappe.get_all(doctype):
+		_doc = frappe.get_doc(doctype, doc.name)
+		user = frappe.db.get_value(doctype, doc.name, 'user')
+
+		if not user: continue
+
+		_doc.append('applicable_for_users', {
+			'user': user
+		})
+		_doc.pos_profile_name = user + ' - ' + _doc.company
+		_doc.save()
diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js
index 1b67ff2..a8093fd 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.js
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.js
@@ -261,20 +261,57 @@
 	}
 
 	setup_pos_profile() {
-		return frappe.call({
-			method: 'erpnext.stock.get_item_details.get_pos_profile',
-			args: {
-				company: frappe.sys_defaults.company
-			}
-		}).then(r => {
-			this.pos_profile = r.message;
+		return new Promise((resolve) => {
+			const on_submit = ({ pos_profile }) => {
+				this.get_pos_profile_doc(pos_profile)
+					.then(doc => {
+						this.pos_profile = doc;
 
-			if (!this.pos_profile) {
-				this.pos_profile = {
-					currency: frappe.defaults.get_default('currency'),
-					selling_price_list: frappe.defaults.get_default('selling_price_list')
-				};
+						if (!this.pos_profile) {
+							this.pos_profile = {
+								currency: frappe.defaults.get_default('currency'),
+								selling_price_list: frappe.defaults.get_default('selling_price_list')
+							};
+						}
+
+						resolve();
+					});
 			}
+
+			frappe.call({
+				method: 'erpnext.accounts.doctype.pos_profile.pos_profile.get_pos_profiles_for_user'
+			})
+			.then((r) => {
+				if (r && r.message) {
+					const pos_profiles = r.message;
+
+					if(pos_profiles.length === 1) {
+						// load profile directly
+						on_submit({pos_profile: pos_profiles[0]});
+					} else {
+						// ask prompt
+						frappe.prompt(
+							[{ fieldtype: 'Select', label: 'POS Profile', options: pos_profiles }],
+							on_submit,
+							__('Select POS Profile')
+						)
+					}
+				}
+			});
+		});
+	}
+
+	get_pos_profile_doc(pos_profile_name) {
+		return new Promise(resolve => {
+			frappe.call({
+				method: 'erpnext.accounts.doctype.pos_profile.pos_profile.get_pos_profile',
+				args: {
+					pos_profile_name
+				},
+				callback: (r) => {
+					resolve(r.message);
+				}
+			});
 		});
 	}