diff --git a/erpnext/public/js/pos/pos.js b/erpnext/public/js/pos/pos.js index 961071cf45..e848bc439b 100644 --- a/erpnext/public/js/pos/pos.js +++ b/erpnext/public/js/pos/pos.js @@ -57,7 +57,7 @@ erpnext.pos.PointOfSale = Class.extend({ "fieldtype": "Link", "options": this.party, "label": this.party, - "fieldname": "pos_party", + "fieldname": this.party.toLowerCase(), "placeholder": this.party }, parent: this.wrapper.find(".party-area"), @@ -415,6 +415,9 @@ erpnext.pos.PointOfSale = Class.extend({ // prefer cash payment! var default_mode = me.frm.doc.mode_of_payment ? me.frm.doc.mode_of_payment : me.modes_of_payment.indexOf(__("Cash"))!==-1 ? __("Cash") : undefined; + + var smallest_currency_fraction_value = flt(frappe.model.get_value(":Currency", + me.frm.doc.currency, "smallest_currency_fraction_value")) // show payment wizard var dialog = new frappe.ui.Dialog({ @@ -422,8 +425,8 @@ erpnext.pos.PointOfSale = Class.extend({ title: 'Payment', fields: [ {fieldtype:'Currency', - fieldname:'total_amount', label: __('Total Amount'), read_only:1, - "default": me.frm.doc.grand_total, read_only: 1}, + fieldname:'total_amount', label: __('Total Amount'), + "default": me.frm.doc.grand_total}, {fieldtype:'Select', fieldname:'mode_of_payment', label: __('Mode of Payment'), options: me.modes_of_payment.join('\n'), reqd: 1, @@ -431,7 +434,18 @@ erpnext.pos.PointOfSale = Class.extend({ {fieldtype:'Currency', fieldname:'paid_amount', label:__('Amount Paid'), reqd:1, "default": me.frm.doc.grand_total, hidden: 1, change: function() { var values = dialog.get_values(); - dialog.set_value("change", Math.round(values.paid_amount - values.total_amount)); + + var actual_change = flt(values.paid_amount - values.total_amount, + precision("paid_amount")); + + if (actual_change > 0) { + var rounded_change = actual_change - remainder(actual_change, + smallest_currency_fraction_value, precision("paid_amount")); + } else { + var rounded_change = 0; + } + + dialog.set_value("change", rounded_change); dialog.get_input("change").trigger("change"); }},