diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json index 187454ef33..a7c2c3df37 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, @@ -11,6 +11,36 @@ "doctype": "DocType", "editable_grid": 0, "fields": [ + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "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, @@ -416,6 +446,67 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "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, @@ -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 8d6a2db470..6b7d99f7f1 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py @@ -11,7 +11,7 @@ from frappe.model.document import Document 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,45 @@ class POSProfile(Document): @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=None): + if not pos_profile_name: return + name = frappe.db.get_value('POS Profile', { 'pos_profile_name': pos_profile_name }) + return frappe.get_doc('POS Profile', name) diff --git a/erpnext/accounts/doctype/pos_profile_user/__init__.py b/erpnext/accounts/doctype/pos_profile_user/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.js b/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.js new file mode 100644 index 0000000000..f0884ebef5 --- /dev/null +++ b/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.js @@ -0,0 +1,6 @@ +// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('POS Profile User', { + +}); diff --git a/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.json b/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.json new file mode 100644 index 0000000000..22c7f722e2 --- /dev/null +++ b/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.json @@ -0,0 +1,93 @@ +{ + "allow_copy": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "beta": 0, + "creation": "2017-10-27 16:46:06.060930", + "custom": 0, + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "user", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "User", + "length": 0, + "no_copy": 0, + "options": "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 + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "idx": 0, + "image_view": 0, + "in_create": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 0, + "max_attachments": 0, + "modified": "2017-10-27 16:46:12.784244", + "modified_by": "Administrator", + "module": "Accounts", + "name": "POS Profile User", + "name_case": "", + "owner": "Administrator", + "permissions": [ + { + "amend": 0, + "apply_user_permissions": 0, + "cancel": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "if_owner": 0, + "import": 0, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "set_user_permissions": 0, + "share": 1, + "submit": 0, + "write": 1 + } + ], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1, + "track_seen": 0 +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.py b/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.py new file mode 100644 index 0000000000..d77cddea61 --- /dev/null +++ b/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +from frappe.model.document import Document + +class POSProfileUser(Document): + pass diff --git a/erpnext/patches.txt b/erpnext/patches.txt index fd7a1b4da6..5f5b46ba40 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -448,6 +448,7 @@ erpnext.patches.v8_9.remove_employee_from_salary_structure_parent erpnext.patches.v8_9.delete_gst_doctypes_for_outside_india_accounts erpnext.patches.v8_9.set_default_fields_in_variant_settings erpnext.patches.v8_9.update_billing_gstin_for_indian_account +erpnext.patches.v9_0.add_user_to_child_table_in_pos_profile erpnext.patches.v9_0.set_schedule_date_for_material_request_and_purchase_order erpnext.patches.v9_0.student_admission_childtable_migrate erpnext.patches.v9_0.fix_subscription_next_date #2017-10-23 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 0000000000..b2093c6c6f --- /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 196bb960df..2f6ccdb7b7 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -283,25 +283,64 @@ erpnext.pos.PointOfSale = class PointOfSale { } setup_pos_profile() { + return new Promise((resolve) => { + + const load_default = () => { + this.pos_profile = { + company: this.company, + currency: frappe.defaults.get_default('currency'), + selling_price_list: frappe.defaults.get_default('selling_price_list') + }; + resolve(); + } + + const on_submit = ({ pos_profile }) => { + this.get_pos_profile_doc(pos_profile) + .then(doc => { + this.pos_profile = doc; + if (!this.pos_profile) { + load_default(); + } + 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.filter(a => a); + + if (pos_profiles.length === 0) { + load_default(); + } else 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.stock.get_item_details.get_pos_profile', + method: 'erpnext.accounts.doctype.pos_profile.pos_profile.get_pos_profile', args: { - company: this.company + pos_profile_name + }, + callback: (r) => { + resolve(r.message); } - }).then(r => { - this.pos_profile = r.message; - - if (!this.pos_profile) { - this.pos_profile = { - company: this.company, - currency: frappe.defaults.get_default('currency'), - selling_price_list: frappe.defaults.get_default('selling_price_list') - }; - } - resolve(); }); - }) + }); } setup_company() {