From 88655890be7279cbe0bf910ca100218288e7a73c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 28 May 2015 10:47:55 +0530 Subject: [PATCH] [fix] [refactor] pos hangs in multi-company, if company is not set --- .../doctype/sales_invoice/sales_invoice.js | 6 ++-- erpnext/public/js/pos/pos.js | 32 ++++++++++++------- erpnext/public/js/pos/pos_bill_item.html | 4 +-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index d166638047..57e17b6da6 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -23,7 +23,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte this.frm.set_value("is_pos", 1); this.is_pos(function() { if (cint(frappe.defaults.get_user_defaults("fs_pos_view"))===1) - erpnext.pos.toggle(me.frm); + erpnext.pos.toggle(me.frm, true); }); } } @@ -75,7 +75,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte } // Show buttons only when pos view is active - if (doc.docstatus===0 && !this.pos_active) { + if (doc.docstatus===0 && !cur_frm.page.current_view_name!=="pos") { cur_frm.cscript.sales_order_btn(); cur_frm.cscript.delivery_note_btn(); } @@ -253,7 +253,7 @@ cur_frm.cscript.mode_of_payment = function(doc) { if(r.message) { cur_frm.set_value("cash_bank_account", r.message["account"]); } - + } }); } diff --git a/erpnext/public/js/pos/pos.js b/erpnext/public/js/pos/pos.js index 46585f9737..da82ba2280 100644 --- a/erpnext/public/js/pos/pos.js +++ b/erpnext/public/js/pos/pos.js @@ -331,7 +331,7 @@ erpnext.pos.PointOfSale = Class.extend({ }, set_primary_action: function() { var me = this; - if (!this.frm.pos_active) return; + if (this.frm.page.current_view_name==="main") return; if (this.frm.doctype == "Sales Invoice" && this.frm.doc.docstatus===0) { if (!this.frm.doc.is_pos) { @@ -342,7 +342,6 @@ erpnext.pos.PointOfSale = Class.extend({ }); } else if (this.frm.doc.docstatus===1) { this.frm.page.set_primary_action(__("New"), function() { - me.frm.pos_active = false; erpnext.open_as_pos = true; new_doc(me.frm.doctype); }); @@ -498,8 +497,8 @@ erpnext.pos.make_pos_btn = function(frm) { erpnext.pos.toggle(frm) }); } - if(erpnext.open_as_pos && !frm.pos_active) { - erpnext.pos.toggle(frm); + if(erpnext.open_as_pos && frm.page.current_view_name !== "pos") { + erpnext.pos.toggle(frm, true); } } @@ -508,12 +507,24 @@ erpnext.pos.toggle = function(frm, show) { var price_list = frappe.meta.has_field(cur_frm.doc.doctype, "selling_price_list") ? frm.doc.selling_price_list : frm.doc.buying_price_list; - if((show===true && frm.pos_active) || (show===false && !frm.pos_active)) { - return; + if(show!==undefined) { + if((show===true && frm.page.current_view_name === "pos") + || (show===false && frm.page.current_view_name === "main")) { + return; + } } - if(show && !price_list) { - frappe.throw(__("Please select Price List")); + console.log(frm.page.current_view_name); + + if(frm.page.current_view_name!=="pos") { + // before switching, ask for pos name + if(!price_list) { + frappe.throw(__("Please select Price List")); + } + + if(!frm.doc.company) { + frappe.throw(__("Please select Company")); + } } // make pos @@ -523,14 +534,13 @@ erpnext.pos.toggle = function(frm, show) { } // toggle view - frm.page.set_view(frm.pos_active ? "main" : "pos"); - frm.pos_active = !frm.pos_active; + frm.page.set_view(frm.page.current_view_name==="pos" ? "main" : "pos"); frm.toolbar.current_status = null; frm.refresh(); // refresh - if(frm.pos_active) { + if(frm.page.current_view_name==="pos") { frm.pos.refresh(); } } diff --git a/erpnext/public/js/pos/pos_bill_item.html b/erpnext/public/js/pos/pos_bill_item.html index ffbebe469c..c93c76caa6 100644 --- a/erpnext/public/js/pos/pos_bill_item.html +++ b/erpnext/public/js/pos/pos_bill_item.html @@ -9,8 +9,8 @@ {% if(actual_qty != null) { %}
- {%= actual_qty %} - ({%= projected_qty %}) + {%= actual_qty || 0 %} + ({%= projected_qty || 0 %})
{% } %}