From d8de921c400265d4cfef195d1e8379ba2a6e857d Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 6 Mar 2014 15:40:22 +0530 Subject: [PATCH] fixed erpnext/frappe#1441 and other pos related cleanups --- erpnext/accounts/doctype/sales_invoice/pos.js | 57 +++++++++++-------- erpnext/accounts/doctype/sales_invoice/pos.py | 2 +- .../doctype/sales_invoice/sales_invoice.js | 2 - erpnext/selling/sales_common.js | 16 +++--- erpnext/setup/install.py | 1 + 5 files changed, 44 insertions(+), 34 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.js b/erpnext/accounts/doctype/sales_invoice/pos.js index 480ce02626..fc6190ae7a 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.js +++ b/erpnext/accounts/doctype/sales_invoice/pos.js @@ -19,7 +19,7 @@ erpnext.POS = Class.extend({ \ \ \ - \ + \ \ \ \ @@ -35,7 +35,7 @@ erpnext.POS = Class.extend({
\
Item'+__("Item")+'Qty
\ \ - \ + \ \ \
Net Total'+__("Net Total")+'
\ @@ -44,7 +44,7 @@ erpnext.POS = Class.extend({ \ \ \ - \ + \ \ \ \ @@ -55,7 +55,7 @@ erpnext.POS = Class.extend({
\
Taxes'+__("Taxes")+'
\ \ - \ + \ \
Discount Amount'+__("Discount Amount")+'\ \ \ \ - \ + \ \ \
Grand Total'+__("Grand Total")+'
\ \ + \ \ \

\
\
\ \ + '+__("Make Payment")+'\
\
\ \ + '+__("Del")+'\
\
\

\ @@ -439,6 +448,12 @@ erpnext.POS = Class.extend({ me.frm.doc.currency)); this.wrapper.find(".grand-total").text(format_currency(this.frm.doc[this.grand_total], me.frm.doc.currency)); + + $(".paid-amount-area").toggle(!!this.frm.doc.paid_amount); + if(this.frm.doc.paid_amount) { + this.wrapper.find(".paid-amount").text(format_currency(this.frm.doc.paid_amount, + me.frm.doc.currency)); + } }, call_when_local: function() { var me = this; @@ -484,25 +499,16 @@ erpnext.POS = Class.extend({ disable_text_box_and_button: function() { var me = this; // if form is submitted & cancelled then disable all input box & buttons - if (this.frm.doc.docstatus>=1) { - $(this.wrapper).find('input, button').each(function () { - $(this).prop('disabled', true); - }); - $(this.wrapper).find(".remove-items").hide(); - $(this.wrapper).find(".make-payment").hide(); - } - else { - $(this.wrapper).find('input, button').each(function () { - $(this).prop('disabled', false); - }); - $(this.wrapper).find(".make-payment").show(); - } + $(this.wrapper) + .find(".remove-items, .make-payment, .increase-qty, .decrease-qty") + .toggle(this.frm.doc.docstatus===0); + + $(this.wrapper).find('input, button').prop("disabled", !(this.frm.doc.docstatus===0)); }, hide_payment_button: function() { - var me = this; - // Show Make Payment button only in Sales Invoice - if (this.frm.doctype != "Sales Invoice") - $(this.wrapper).find(".make-payment").hide(); + $(this.wrapper) + .find(".make-payment") + .toggle(this.frm.doctype == "Sales Invoice" && this.frm.doc.is_pos); }, refresh_delete_btn: function() { $(this.wrapper).find(".remove-items").toggle($(".item-cart .warning").length ? true : false); @@ -568,6 +574,9 @@ erpnext.POS = Class.extend({ frappe.call({ method: 'erpnext.accounts.doctype.sales_invoice.pos.get_mode_of_payment', callback: function(r) { + if(!r.message.length) { + msgprint(__("Please add to Modes of Payment from Setup.")) + } for (x=0; x<=r.message.length - 1; x++) { mode_of_payment.push(r.message[x].name); } diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index 2286ed6b81..c2d7c4b4e5 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -49,4 +49,4 @@ def get_item_code(barcode_serial_no): @frappe.whitelist() def get_mode_of_payment(): - return frappe.db.sql("""select name from `tabMode of Payment`""", as_dict=1) \ No newline at end of file + return frappe.get_list("Mode of Payment") diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index ac9768b45a..fdbead9ee3 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -184,8 +184,6 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte this.frm.set_value("write_off_amount", flt(this.frm.doc.grand_total - this.frm.doc.paid_amount), precision("write_off_amount")); } - - this.frm.script_manager.trigger("write_off_amount"); }, write_off_amount: function() { diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 1b48a8e2bc..12aca892d6 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -403,13 +403,15 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ // paid_amount and write_off_amount is only for POS Invoice // total_advance is only for non POS Invoice if(this.frm.doc.doctype == "Sales Invoice" && this.frm.doc.docstatus==0) { - frappe.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount", - "paid_amount"]); - var total_amount_to_pay = this.frm.doc.grand_total - this.frm.doc.write_off_amount - this.frm.doc.total_advance; - this.frm.doc.paid_amount = this.frm.doc.is_pos? flt(total_amount_to_pay): 0.0; - - this.frm.doc.outstanding_amount = flt(total_amount_to_pay - this.frm.doc.paid_amount, - precision("outstanding_amount")); + if(this.frm.doc.paid_amount==null) { + frappe.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount", + "paid_amount"]); + var total_amount_to_pay = this.frm.doc.grand_total - this.frm.doc.write_off_amount + - this.frm.doc.total_advance; + this.frm.doc.paid_amount = this.frm.doc.is_pos ? flt (total_amount_to_pay) : 0.0; + this.frm.set_value("outstanding_amount", flt(total_amount_to_pay + - this.frm.doc.paid_amount, precision("outstanding_amount"))); + } } }, diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index 35e3534bfa..9633f61f01 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -102,6 +102,7 @@ def import_defaults(): {'uom_name': 'Set', 'doctype': 'UOM', 'name': 'Set', "must_be_whole_number": 1}, {'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'}, {'uom_name': 'Minute', 'doctype': 'UOM', 'name': 'Minute'}, + ] from frappe.modules import scrub