Skip to content

Commit

Permalink
fix: allocate amt for payment term invoices
Browse files Browse the repository at this point in the history
(cherry picked from commit ac28a5b)
  • Loading branch information
GursheenK authored and mergify[bot] committed Oct 10, 2023
1 parent 24852e4 commit b22ac13
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,20 +858,25 @@ frappe.ui.form.on('Payment Entry', {
}
}

let outstanding_amount;
$.each(frm.doc.references || [], function(i, row) {
if (frappe.flags.allocate_payment_amount == 0) {
//If allocate payment amount checkbox is unchecked, set zero to allocate amount
row.allocated_amount = 0;

} else if (frappe.flags.allocate_payment_amount != 0 && (!row.allocated_amount || paid_amount_change)) {
if (row.outstanding_amount > 0 && allocated_positive_outstanding >= 0) {
row.allocated_amount = (row.outstanding_amount >= allocated_positive_outstanding) ?
allocated_positive_outstanding : row.outstanding_amount;
} else if (frappe.flags.allocate_payment_amount != 0 && (row.payment_term || !row.allocated_amount || paid_amount_change)) {
if(row.payment_term)
outstanding_amount = row.allocated_amount;
else
outstanding_amount = row.outstanding_amount;
if (outstanding_amount > 0 && allocated_positive_outstanding >= 0) {
row.allocated_amount = (outstanding_amount >= allocated_positive_outstanding) ?
allocated_positive_outstanding : outstanding_amount;
allocated_positive_outstanding -= flt(row.allocated_amount);

} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
row.allocated_amount = (Math.abs(row.outstanding_amount) >= allocated_negative_outstanding) ?
-1*allocated_negative_outstanding : row.outstanding_amount;
} else if (outstanding_amount < 0 && allocated_negative_outstanding) {
row.allocated_amount = (Math.abs(outstanding_amount) >= allocated_negative_outstanding) ?
-1*allocated_negative_outstanding : outstanding_amount;
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
}
}
Expand Down

0 comments on commit b22ac13

Please sign in to comment.