Load default pos profile if not found

This commit is contained in:
Faris Ansari 2017-10-31 21:56:16 +05:30
parent 895aa7b7ac
commit 3d59179205
2 changed files with 17 additions and 9 deletions

View File

@ -132,6 +132,7 @@ def get_pos_profiles_for_user(user=None):
return out return out
@frappe.whitelist() @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 }) name = frappe.db.get_value('POS Profile', { 'pos_profile_name': pos_profile_name })
return frappe.get_doc('POS Profile', name) return frappe.get_doc('POS Profile', name)

View File

@ -284,17 +284,22 @@ erpnext.pos.PointOfSale = class PointOfSale {
setup_pos_profile() { setup_pos_profile() {
return new Promise((resolve) => { 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) { const load_default = () => {
this.pos_profile = { this.pos_profile = {
company: this.company, company: this.company,
currency: frappe.defaults.get_default('currency'), currency: frappe.defaults.get_default('currency'),
selling_price_list: frappe.defaults.get_default('selling_price_list') 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(); resolve();
}); });
@ -304,9 +309,11 @@ erpnext.pos.PointOfSale = class PointOfSale {
method: 'erpnext.accounts.doctype.pos_profile.pos_profile.get_pos_profiles_for_user' method: 'erpnext.accounts.doctype.pos_profile.pos_profile.get_pos_profiles_for_user'
}).then((r) => { }).then((r) => {
if (r && r.message) { 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 // load profile directly
on_submit({pos_profile: pos_profiles[0]}); on_submit({pos_profile: pos_profiles[0]});
} else { } else {