From 23607f91cd949a91e848b43d19903845cff689ff Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 8 Aug 2014 17:23:40 +0530 Subject: [PATCH] [fix] [pos] pos view only for draft docs --- .../doctype/sales_invoice/sales_invoice.js | 3 +- erpnext/public/js/transaction.js | 70 ++++++++++--------- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index fda6548d72..76092ed30d 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -73,8 +73,9 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte return item.delivery_note ? true : false; }); - if(!from_delivery_note) + if(!from_delivery_note) { cur_frm.appframe.add_primary_action(__('Make Delivery'), cur_frm.cscript['Make Delivery Note'], "icon-truck") + } } if(doc.outstanding_amount!=0) { diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index 44835ce04d..915bbd9eb3 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -57,27 +57,32 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ this.set_dynamic_labels(); // Show POS button only if it is enabled from features setup - if(cint(sys_defaults.fs_pos_view)===1 && this.frm.doctype!="Material Request" && this.frm.doc.docstatus===0) + if(cint(sys_defaults.fs_pos_view)===1 && this.frm.doctype!="Material Request") this.make_pos_btn(); }, make_pos_btn: function() { - if(!this.pos_active) { - var btn_label = __("POS View"), - icon = "icon-th"; - } else { - var btn_label = __("Form View"), - icon = "icon-file-text"; - } var me = this; + if(this.frm.doc.docstatus===0) { + if(!this.pos_active) { + var btn_label = __("POS View"), + icon = "icon-th"; + } else { + var btn_label = __("Form View"), + icon = "icon-file-text"; + } - this.$pos_btn = this.frm.appframe.add_primary_action(btn_label, function() { - me.toggle_pos(); - }, icon, "btn-default"); + if(erpnext.open_as_pos) { + me.toggle_pos(true); + erpnext.open_as_pos = false; + } - if(erpnext.open_as_pos) { - me.toggle_pos(true); - erpnext.open_as_pos = false; + this.$pos_btn = this.frm.appframe.add_primary_action(btn_label, function() { + me.toggle_pos(); + }, icon, "btn-default"); + } else { + // hack: will avoid calling refresh from refresh + setTimeout(function() { me.toggle_pos(false); }, 100); } }, @@ -86,26 +91,27 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ var price_list = frappe.meta.has_field(cur_frm.doc.doctype, "selling_price_list") ? this.frm.doc.selling_price_list : this.frm.doc.buying_price_list; - if (!price_list) - msgprint(__("Please select Price List")) - else { - if((show===true && this.pos_active) || (show===false && !this.pos_active)) return; + if((show===true && this.pos_active) || (show===false && !this.pos_active)) + return; - // make pos - if(!this.frm.pos) { - this.frm.layout.add_view("pos"); - this.frm.pos = new erpnext.POS(this.frm.layout.views.pos, this.frm); - } - - // toggle view - this.frm.layout.set_view(this.pos_active ? "" : "pos"); - this.pos_active = !this.pos_active; - - // refresh - if(this.pos_active) - this.frm.pos.refresh(); - this.frm.refresh(); + if(show && !price_list) { + frappe.throw(__("Please select Price List")); } + + // make pos + if(!this.frm.pos) { + this.frm.layout.add_view("pos"); + this.frm.pos = new erpnext.POS(this.frm.layout.views.pos, this.frm); + } + + // toggle view + this.frm.layout.set_view(this.pos_active ? "" : "pos"); + this.pos_active = !this.pos_active; + + // refresh + if(this.pos_active) + this.frm.pos.refresh(); + this.frm.refresh(); },