From 16a62fa4becce3bfd72c1826d313f836dd01ff52 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 23 Aug 2013 13:16:22 +0530 Subject: [PATCH] [pos] [cleanup] --- accounts/doctype/sales_invoice/pos.js | 193 +++++++++++------- accounts/doctype/sales_invoice/pos.py | 14 +- .../doctype/sales_invoice/sales_invoice.js | 18 +- startup/install.py | 2 +- utilities/make_demo.py | 3 +- 5 files changed, 141 insertions(+), 89 deletions(-) diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js index c27adc3a574..126b88745cd 100644 --- a/accounts/doctype/sales_invoice/pos.js +++ b/accounts/doctype/sales_invoice/pos.js @@ -7,56 +7,66 @@ erpnext.POS = Class.extend({ this.frm = frm; this.wrapper.html('
\
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
 
\ -
\ - \ - \ - \ - \ - \ - \ - \ -
Item#RateAmount
\ -
\ - \ +
\ +
\ +
\ +
\ + \ +
\ +
\ +
\ +
\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
ItemQtyRate
\ +
\ +
\ +
\ + \ + \ + \ + \ + \ +
Net Total
\ + \ + \ + \ + \ + \ + \
Grand Total
\
\
\ -
 
\ -
\ -
Net Total
\ -
 
\ -
\ -
\ -
Tax
\ -
 
\ -
\ -
\ -
Grand Total
\ -
 
\ -
\ +

\ + \ + \ +

\
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ +
\
\ -
\ +
\
\
\
\ @@ -91,7 +101,8 @@ erpnext.POS = Class.extend({ "fieldtype": "Link", "options": "Customer", "label": "Customer", - "fieldname": "pos_customer" + "fieldname": "pos_customer", + "placeholder": "Customer" }, parent: this.wrapper.find(".customer-area") }); @@ -108,7 +119,8 @@ erpnext.POS = Class.extend({ "fieldtype": "Link", "options": "Item Group", "label": "Item Group", - "fieldname": "pos_item_group" + "fieldname": "pos_item_group", + "placeholder": "Filter by Item Group" }, parent: this.wrapper.find(".item-group-area") }); @@ -125,7 +137,8 @@ erpnext.POS = Class.extend({ "fieldtype": "Link", "options": "Item", "label": "Item", - "fieldname": "pos_item" + "fieldname": "pos_item", + "placeholder": "Select Item" }, parent: this.wrapper.find(".search-area") }); @@ -141,7 +154,8 @@ erpnext.POS = Class.extend({ df: { "fieldtype": "Data", "label": "Barcode", - "fieldname": "pos_barcode" + "fieldname": "pos_barcode", + "placeholder": "Select Barcode" }, parent: this.wrapper.find(".barcode-area") }); @@ -164,28 +178,30 @@ erpnext.POS = Class.extend({ me.wrapper.find(".item-list").empty(); $.each(r.message, function(index, obj) { if (obj.image) - image = ""; + image = ""; else - image = "
"; + image = '
'; - $(repl('', + $(repl('
\ + %(item_image)s\ +
%(item_code)s
\ +
%(item_name)s
\ +
%(item_price)s
\ +
', { item_code: obj.name, item_price: format_currency(obj.ref_rate, obj.ref_currency), - item_name: obj.item_name, + item_name: obj.name===obj.item_name ? "" : obj.item_name, item_image: image })).appendTo($wrap); }); - $("div.item").on("click", function() { - me.add_to_cart($(this).find("a").attr("data-item_code")); + $("div.pos-item").on("click", function() { + if(!cur_frm.doc.customer) { + msgprint("Please select customer first."); + return; + } + me.add_to_cart($(this).attr("data-item_code")); }); } }); @@ -195,7 +211,7 @@ erpnext.POS = Class.extend({ var caught = false; // get no_of_items - no_of_items = me.wrapper.find("#cart tr").length; + no_of_items = me.wrapper.find("#cart tbody").length; // check whether the item is already added if (no_of_items != 0) { @@ -214,7 +230,7 @@ erpnext.POS = Class.extend({ var child = wn.model.add_child(me.frm.doc, "Sales Invoice Item", "entries"); child.item_code = item_code; me.frm.cscript.item_code(me.frm.doc, child.doctype, child.name); - me.refresh(); + //me.refresh(); } }, update_qty: function(item_code, qty) { @@ -238,18 +254,19 @@ erpnext.POS = Class.extend({ this.barcode.set_input(""); // add items - var $items = me.wrapper.find("#cart").empty(); + var $items = me.wrapper.find("#cart tbody").empty(); $.each(wn.model.get_children("Sales Invoice Item", this.frm.doc.name, "entries", - "Sales Invoice"), function(i, d) { + "Sales Invoice"), function(i, d) { $(repl('\ - %(item_code)s
%(item_name)s\ - \ - %(rate)s\ - %(amount)s', + %(item_code)s%(item_name)s\ + \ + %(rate)s
%(amount)s\ + ', { item_code: d.item_code, - item_name: d.item_name, + item_name: d.item_name===d.item_code ? "" : ("
" + d.item_name), qty: d.qty, rate: format_currency(d.ref_rate, cur_frm.doc.price_list_currency), amount: format_currency(d.export_amount, cur_frm.doc.price_list_currency) @@ -257,11 +274,26 @@ erpnext.POS = Class.extend({ )).appendTo($items); }); + // taxes + var taxes = wn.model.get_children("Sales Taxes and Charges", this.frm.doc.name, "other_charges", + "Sales Invoice"); + $(".tax-table") + .toggle((taxes && taxes.length) ? true : false) + .find("tbody").empty(); + + $.each(taxes, function(i, d) { + $(repl('\ + %(description)s\ + %(tax_amount)s\ + ', { + description: d.description, + tax_amount: format_currency(d.tax_amount, me.frm.doc.price_list_currency) + })).appendTo(".tax-table tbody") + }); + // set totals this.wrapper.find(".net-total").text(format_currency(this.frm.doc.net_total_export, cur_frm.doc.price_list_currency)); - this.wrapper.find(".tax").text(format_currency(this.frm.doc.other_charges_total_export, - cur_frm.doc.price_list_currency)); this.wrapper.find(".grand-total").text(format_currency(this.frm.doc.grand_total_export, cur_frm.doc.price_list_currency)); @@ -282,7 +314,14 @@ erpnext.POS = Class.extend({ row.prop("class", null); row.attr("data-selected", "false"); } + me.refresh_delete_btn(); + }); + + me.refresh_delete_btn(); + }, + refresh_delete_btn: function() { + $(".delete-items").toggle($(".item-cart .warning").length ? true : false); }, add_item_thru_barcode: function() { var me = this; @@ -302,9 +341,9 @@ erpnext.POS = Class.extend({ remove_selected_item: function() { var me = this; var selected_items = []; - var no_of_items = $("#cart tr").length; + var no_of_items = $("#cart tbody tr").length; for(var x=0; x<=no_of_items - 1; x++) { - var row = $("#cart tr:eq(" + x + ")"); + var row = $("#cart tbody tr:eq(" + x + ")"); if(row.attr("data-selected") == "true") { selected_items.push(row.attr("id")); } @@ -327,7 +366,7 @@ erpnext.POS = Class.extend({ }, make_payment: function() { var me = this; - var no_of_items = $("#cart tr").length; + var no_of_items = $("#cart tbody tr").length; var mode_of_payment = []; if (no_of_items == 0) @@ -356,6 +395,8 @@ erpnext.POS = Class.extend({ }); dialog.show(); + dialog.get_input("total_amount").attr("disabled", "disabled"); + dialog.fields_dict.pay.input.onclick = function() { cur_frm.set_value("mode_of_payment", dialog.get_values().mode_of_payment); cur_frm.set_value("paid_amount", dialog.get_values().total_amount); diff --git a/accounts/doctype/sales_invoice/pos.py b/accounts/doctype/sales_invoice/pos.py index f7dacf19a65..2f2ad6a36c2 100644 --- a/accounts/doctype/sales_invoice/pos.py +++ b/accounts/doctype/sales_invoice/pos.py @@ -9,14 +9,18 @@ def get_items(price_list, item=None, item_group=None): condition = "" if item_group and item_group != "All Item Groups": - condition = "where i.item_group='%s'" % item_group + condition = "and i.item_group='%s'" % item_group if item: - condition = "where i.name='%s'" % item + condition = "and i.name='%s'" % item - return webnotes.conn.sql("""select i.name, i.item_name, i.image, ip.ref_rate, - ip.ref_currency from `tabItem` i LEFT JOIN `tabItem Price` ip ON ip.parent=i.name - and ip.price_list=%s %s""" % ('%s', condition), (price_list), as_dict=1) + return webnotes.conn.sql("""select + i.name, i.item_name, i.image, ip.ref_rate, ip.ref_currency + from `tabItem` i LEFT JOIN `tabItem Price` ip + ON ip.parent=i.name + and ip.price_list=%s + where + i.is_sales_item='Yes'%s""" % ('%s', condition), (price_list), as_dict=1) @webnotes.whitelist() def get_item_from_barcode(barcode): diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index 3baa2268846..5d11ecbecb5 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -26,8 +26,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte } } - pos_view = cint(sys_defaults.fs_pos_view); - if(this.frm.doc.is_pos && this.frm.doc.docstatus===0 && pos_view===1) { + if(this.frm.doc.is_pos && this.frm.doc.docstatus===0) { cur_frm.cscript.toggle_pos(true); } }, @@ -60,7 +59,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher); } - if (this.frm.doc.docstatus===0) { + if (doc.docstatus===0) { cur_frm.add_custom_button(wn._('From Sales Order'), function() { wn.model.map_current_doc({ @@ -97,11 +96,18 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte if (cint(sys_defaults.fs_pos_view)===1) cur_frm.cscript.pos_btn(); + + setTimeout(function() { cur_frm.$pos_btn.click(); }, 1000); + + } else { + // hide shown pos for submitted records + if(cur_frm.pos_active) cur_frm.cscript.toggle_pos(false); } }, pos_btn: function() { - if(cur_frm.$pos_btn) cur_frm.$pos_btn.remove(); + if(cur_frm.$pos_btn) + cur_frm.$pos_btn.remove(); if(!cur_frm.pos_active) { var btn_label = wn._("POS View"), @@ -111,11 +117,11 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte icon = "icon-file-text"; } - cur_frm.add_custom_button(btn_label, function() { - cur_frm.$pos_btn = $(this); + cur_frm.$pos_btn = cur_frm.add_custom_button(btn_label, function() { cur_frm.cscript.toggle_pos(); cur_frm.cscript.pos_btn(); }, icon); + }, toggle_pos: function(show) { diff --git a/startup/install.py b/startup/install.py index 7e9273ca586..ea281b8ea77 100644 --- a/startup/install.py +++ b/startup/install.py @@ -72,7 +72,7 @@ def feature_setup(): 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts', 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras', 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality', - 'fs_page_break', 'fs_more_info' + 'fs_page_break', 'fs_more_info', 'fs_pos_view' ] doc.fields.update(dict(zip(flds, [1]*len(flds)))) doc.save() diff --git a/utilities/make_demo.py b/utilities/make_demo.py index 809a12b6c5c..28841441354 100644 --- a/utilities/make_demo.py +++ b/utilities/make_demo.py @@ -24,13 +24,14 @@ bank_name = "Citibank" runs_for = 20 prob = { "default": { "make": 0.6, "qty": (1,5) }, + "Sales Order": { "make": 0.4, "qty": (1,3) }, "Purchase Order": { "make": 0.7, "qty": (1,15) }, "Purchase Receipt": { "make": 0.7, "qty": (1,15) }, } def make(reset=False): webnotes.connect() - webnotes.print_messages = True + #webnotes.print_messages = True webnotes.mute_emails = True webnotes.rollback_on_exception = True