Merge pull request #17261 from rohitwaghchaure/pos_not_working_if_user_can_access_more_than_one_company_develop

fix: POS not working if user has access of multiple company(Cherry-pick)
This commit is contained in:
rohitwaghchaure 2019-04-16 18:44:27 +05:30 committed by GitHub
commit 1ddc123dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(`
<div class="pos">
@ -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);