From ac28a5b372d96badd7ba808308a3f1270943f892 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Fri, 22 Sep 2023 12:41:17 +0530 Subject: [PATCH] fix: allocate amt for payment term invoices --- .../doctype/payment_entry/payment_entry.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 0203c45058..8ae4aa748a 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -874,20 +874,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)); } }