From 82a21beba04bde8ec5b1ee6402c2812b7cef2ecf Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 22 Jan 2014 16:55:32 +0530 Subject: [PATCH 1/2] Item List refresh when price list changed in POS --- accounts/doctype/sales_invoice/pos.js | 52 +++++++++++++++------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js index b71b45e55b..21ccd01eaa 100644 --- a/accounts/doctype/sales_invoice/pos.js +++ b/accounts/doctype/sales_invoice/pos.js @@ -109,6 +109,7 @@ erpnext.POS = Class.extend({ this.party = party; this.price_list = (party == "Customer" ? this.frm.doc.selling_price_list : this.frm.doc.buying_price_list); + this.price_list_field = (party == "Customer" ? "selling_price_list" : "buying_price_list"); this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase"); this.net_total = "net_total_" + export_or_import; this.grand_total = "grand_total_" + export_or_import; @@ -324,10 +325,12 @@ erpnext.POS = Class.extend({ } } }); - me.refresh(); + this.refresh(); }, refresh: function() { var me = this; + + this.refresh_item_list(); this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]); this.barcode.set_input(""); @@ -350,6 +353,14 @@ erpnext.POS = Class.extend({ this.make_party(); } }, + refresh_item_list: function() { + var me = this; + // refresh item list on change of price list + if (this.frm.doc[this.price_list_field] != this.price_list) { + this.price_list = this.frm.doc[this.price_list_field]; + this.make_item_list(); + } + }, show_items_in_item_cart: function() { var me = this; var $items = this.wrapper.find("#cart tbody").empty(); @@ -383,9 +394,8 @@ erpnext.POS = Class.extend({ )).appendTo($items); }); - this.wrapper.find(".increase-qty, .decrease-qty").on("click", function() { - var item_code = $(this).closest("tr").attr("id"); - me.selected_item_qty_operation(item_code, $(this).attr("class")); + this.wrapper.find("input.qty").on("focus", function() { + $(this).select(); }); }, show_taxes: function() { @@ -422,10 +432,16 @@ erpnext.POS = Class.extend({ // append quantity to the respective item after change from input box $(this.wrapper).find("input.qty").on("change", function() { - var item_code = $(this).closest("tr")[0].id; + var item_code = $(this).closest("tr").attr("id"); me.update_qty(item_code, $(this).val()); }); + // increase/decrease qty on plus/minus button + $(this.wrapper).find(".increase-qty, .decrease-qty").on("click", function() { + var tr = $(this).closest("tr"); + me.increase_decrease_qty(tr, $(this).attr("class")); + }); + // on td click toggle the highlighting of row $(this.wrapper).find("#cart tbody tr td").on("click", function() { var row = $(this).closest("tr"); @@ -443,6 +459,15 @@ erpnext.POS = Class.extend({ me.refresh_delete_btn(); this.barcode.$input.focus(); }, + increase_decrease_qty: function(tr, operation) { + var item_code = tr.attr("id"); + var item_qty = cint(tr.find("input.qty").val()); + + if (operation == "increase-qty") + this.update_qty(item_code, item_qty + 1); + else if (operation == "decrease-qty" && item_qty != 1) + this.update_qty(item_code, item_qty - 1); + }, disable_text_box_and_button: function() { var me = this; // if form is submitted & cancelled then disable all input box & buttons @@ -518,23 +543,6 @@ erpnext.POS = Class.extend({ this.frm.script_manager.trigger("calculate_taxes_and_totals"); this.refresh(); }, - selected_item_qty_operation: function(item_code, operation) { - var me = this; - var child = wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, - this.frm.cscript.fname, this.frm.doctype); - - $.each(child, function(i, d) { - if (d.item_code == item_code) { - if (operation == "increase-qty") - d.qty += 1; - else if (operation == "decrease-qty") - d.qty != 1 ? d.qty -= 1 : d.qty = 1; - - me.frm.script_manager.trigger("qty", d.doctype, d.name); - me.refresh(); - } - }); - }, make_payment: function() { var me = this; var no_of_items = $(this.wrapper).find("#cart tbody tr").length; From 8589b1db2208ea0472480b41614a23066835d178 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 22 Jan 2014 19:25:51 +0530 Subject: [PATCH 2/2] Use model set_value for updating values from POS --- accounts/doctype/sales_invoice/pos.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js index 21ccd01eaa..a594f7f941 100644 --- a/accounts/doctype/sales_invoice/pos.js +++ b/accounts/doctype/sales_invoice/pos.js @@ -270,22 +270,17 @@ erpnext.POS = Class.extend({ this.frm.cscript.fname, this.frm.doctype), function(i, d) { if (d.item_code == item_code) { caught = true; - if (serial_no) { - d.serial_no += '\n' + serial_no; - me.frm.script_manager.trigger("serial_no", d.doctype, d.name); - } - else { - d.qty += 1; - me.frm.script_manager.trigger("qty", d.doctype, d.name); - } + if (serial_no) + wn.model.set_value(d.doctype, d.name, "serial_no", d.serial_no + '\n' + serial_no); + else + wn.model.set_value(d.doctype, d.name, "qty", d.qty + 1); } }); } // if item not found then add new item - if (!caught) { + if (!caught) this.add_new_item_to_grid(item_code, serial_no); - } this.refresh(); this.refresh_search_box(); @@ -320,8 +315,7 @@ erpnext.POS = Class.extend({ wn.model.clear_doc(d.doctype, d.name); me.refresh_grid(); } else { - d.qty = qty; - me.frm.script_manager.trigger("qty", d.doctype, d.name); + wn.model.set_value(d.doctype, d.name, "qty", qty); } } }); @@ -539,6 +533,7 @@ erpnext.POS = Class.extend({ this.refresh_grid(); }, refresh_grid: function() { + this.frm.dirty(); this.frm.fields_dict[this.frm.cscript.fname].grid.refresh(); this.frm.script_manager.trigger("calculate_taxes_and_totals"); this.refresh();