From 3d591792052910c6d97c77f7f056ee788aa10316 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 31 Oct 2017 21:56:16 +0530 Subject: [PATCH] Load default pos profile if not found --- .../doctype/pos_profile/pos_profile.py | 3 ++- .../page/point_of_sale/point_of_sale.js | 23 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py index 3e3728592c..6b7d99f7f1 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py @@ -132,6 +132,7 @@ def get_pos_profiles_for_user(user=None): return out @frappe.whitelist() -def get_pos_profile(pos_profile_name): +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/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js index ee6a633fac..c9893f1ce8 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -284,17 +284,22 @@ 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) { - this.pos_profile = { - company: this.company, - currency: frappe.defaults.get_default('currency'), - selling_price_list: frappe.defaults.get_default('selling_price_list') - }; + load_default(); } resolve(); }); @@ -304,9 +309,11 @@ erpnext.pos.PointOfSale = class PointOfSale { method: 'erpnext.accounts.doctype.pos_profile.pos_profile.get_pos_profiles_for_user' }).then((r) => { if (r && r.message) { - const pos_profiles = r.message; + const pos_profiles = r.message.filter(a => a); - if(pos_profiles.length === 1) { + if (pos_profiles.length === 0) { + load_default(); + } else if(pos_profiles.length === 1) { // load profile directly on_submit({pos_profile: pos_profiles[0]}); } else {