Merge pull request #4632 from nabinhait/pos_fix
Calculate change in POS based on smallest currency fraction value
This commit is contained in:
commit
31608a82f8
@ -57,7 +57,7 @@ erpnext.pos.PointOfSale = Class.extend({
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": this.party,
|
"options": this.party,
|
||||||
"label": this.party,
|
"label": this.party,
|
||||||
"fieldname": "pos_party",
|
"fieldname": this.party.toLowerCase(),
|
||||||
"placeholder": this.party
|
"placeholder": this.party
|
||||||
},
|
},
|
||||||
parent: this.wrapper.find(".party-area"),
|
parent: this.wrapper.find(".party-area"),
|
||||||
@ -415,6 +415,9 @@ erpnext.pos.PointOfSale = Class.extend({
|
|||||||
// prefer cash payment!
|
// prefer cash payment!
|
||||||
var default_mode = me.frm.doc.mode_of_payment ? me.frm.doc.mode_of_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;
|
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
|
// show payment wizard
|
||||||
var dialog = new frappe.ui.Dialog({
|
var dialog = new frappe.ui.Dialog({
|
||||||
@ -422,8 +425,8 @@ erpnext.pos.PointOfSale = Class.extend({
|
|||||||
title: 'Payment',
|
title: 'Payment',
|
||||||
fields: [
|
fields: [
|
||||||
{fieldtype:'Currency',
|
{fieldtype:'Currency',
|
||||||
fieldname:'total_amount', label: __('Total Amount'), read_only:1,
|
fieldname:'total_amount', label: __('Total Amount'),
|
||||||
"default": me.frm.doc.grand_total, read_only: 1},
|
"default": me.frm.doc.grand_total},
|
||||||
{fieldtype:'Select', fieldname:'mode_of_payment',
|
{fieldtype:'Select', fieldname:'mode_of_payment',
|
||||||
label: __('Mode of Payment'),
|
label: __('Mode of Payment'),
|
||||||
options: me.modes_of_payment.join('\n'), reqd: 1,
|
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'),
|
{fieldtype:'Currency', fieldname:'paid_amount', label:__('Amount Paid'),
|
||||||
reqd:1, "default": me.frm.doc.grand_total, hidden: 1, change: function() {
|
reqd:1, "default": me.frm.doc.grand_total, hidden: 1, change: function() {
|
||||||
var values = dialog.get_values();
|
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");
|
dialog.get_input("change").trigger("change");
|
||||||
|
|
||||||
}},
|
}},
|
||||||
|
Loading…
Reference in New Issue
Block a user