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 4c0f42d22e..308b8edd3b 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -54,8 +54,16 @@ erpnext.pos.PointOfSale = class PointOfSale { this.prepare_menu(); this.set_online_status(); }, - () => this.setup_company(), () => this.make_new_invoice(), + () => { + if(!this.frm.doc.company) { + this.setup_company() + .then((company) => { + this.frm.doc.company = company; + this.get_pos_profile(); + }); + } + }, () => { frappe.dom.unfreeze(); }, @@ -63,6 +71,22 @@ erpnext.pos.PointOfSale = class PointOfSale { ]); } + get_pos_profile() { + return frappe.xcall("erpnext.stock.get_item_details.get_pos_profile", + {'company': this.frm.doc.company}) + .then((r) => { + if(r) { + this.frm.doc.pos_profile = r.name; + this.set_pos_profile_data() + .then(() => { + this.on_change_pos_profile(); + }); + } else { + this.raise_exception_for_pos_profile(); + } + }); + } + set_online_status() { this.connection_status = false; this.page.set_indicator(__("Offline"), "grey"); @@ -77,6 +101,11 @@ erpnext.pos.PointOfSale = class PointOfSale { }); } + raise_exception_for_pos_profile() { + setTimeout(() => frappe.set_route('List', 'POS Profile'), 2000); + frappe.throw(__("POS Profile is required to use Point-of-Sale")); + } + prepare_dom() { this.wrapper.append(`
@@ -489,7 +518,7 @@ erpnext.pos.PointOfSale = class PointOfSale { setup_company() { return new Promise(resolve => { - if(!frappe.sys_defaults.company) { + if(!this.frm.doc.company) { frappe.prompt({fieldname:"company", options: "Company", fieldtype:"Link", label: __("Select Company"), reqd: 1}, (data) => { this.company = data.company; @@ -529,6 +558,10 @@ erpnext.pos.PointOfSale = class PointOfSale { return new Promise(resolve => { if (this.frm) { this.frm = get_frm(this.frm); + if(this.company) { + this.frm.doc.company = this.company; + } + resolve(); } else { frappe.model.with_doctype(doctype, () => { @@ -545,6 +578,7 @@ erpnext.pos.PointOfSale = class PointOfSale { frm.refresh(name); frm.doc.items = []; frm.doc.is_pos = 1; + return frm; } } @@ -554,6 +588,10 @@ erpnext.pos.PointOfSale = class PointOfSale { this.frm.doc.company = this.company; } + if (!this.frm.doc.company) { + return; + } + return new Promise(resolve => { return this.frm.call({ doc: this.frm.doc, @@ -562,8 +600,7 @@ erpnext.pos.PointOfSale = class PointOfSale { if(!r.exc) { if (!this.frm.doc.pos_profile) { frappe.dom.unfreeze(); - setTimeout(() => frappe.set_route('List', 'POS Profile'), 2000); - frappe.throw(__("POS Profile is required to use Point-of-Sale")); + this.raise_exception_for_pos_profile(); } this.frm.script_manager.trigger("update_stock"); frappe.model.set_default_values(this.frm.doc);