Skip to content

Commit

Permalink
Merge pull request #36907 from frappe/mergify/bp/version-14-hotfix/pr…
Browse files Browse the repository at this point in the history
…-36899

fix: difference amount calculation logic in Payment Entry UI (backport #36899)
  • Loading branch information
ruthra-kumar authored Sep 1, 2023
2 parents b9a5d54 + 9bc2b41 commit 83e3402
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,9 @@ frappe.ui.form.on('Payment Entry', {
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
}

frm.events.set_unallocated_amount(frm);
// set_unallocated_amount is called by below method,
// no need trigger separately
frm.events.set_total_allocated_amount(frm);
}

// Make read only if Accounts Settings doesn't allow stale rates
Expand All @@ -562,7 +564,9 @@ frappe.ui.form.on('Payment Entry', {
frm.set_value("base_paid_amount", frm.doc.base_received_amount);
}

frm.events.set_unallocated_amount(frm);
// set_unallocated_amount is called by below method,
// no need trigger separately
frm.events.set_total_allocated_amount(frm);
}
frm.set_paid_amount_based_on_received_amount = false;

Expand Down Expand Up @@ -878,12 +882,18 @@ frappe.ui.form.on('Payment Entry', {
},

set_total_allocated_amount: function(frm) {
let exchange_rate = 1;
if (frm.doc.payment_type == "Receive") {
exchange_rate = frm.doc.source_exchange_rate;
} else if (frm.doc.payment_type == "Pay") {
exchange_rate = frm.doc.target_exchange_rate;
}
var total_allocated_amount = 0.0;
var base_total_allocated_amount = 0.0;
$.each(frm.doc.references || [], function(i, row) {
if (row.allocated_amount) {
total_allocated_amount += flt(row.allocated_amount);
base_total_allocated_amount += flt(flt(row.allocated_amount)*flt(row.exchange_rate),
base_total_allocated_amount += flt(flt(row.allocated_amount)*flt(exchange_rate),
precision("base_paid_amount"));
}
});
Expand Down

0 comments on commit 83e3402

Please sign in to comment.