From ac28a5b372d96badd7ba808308a3f1270943f892 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Fri, 22 Sep 2023 12:41:17 +0530 Subject: [PATCH 1/3] 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)); } } From b3aa201eb570167c44225438031438065eef9728 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sat, 23 Sep 2023 14:57:53 +0530 Subject: [PATCH 2/3] fix: split inv allocated amt on server side --- .../doctype/payment_entry/payment_entry.js | 18 +++++++----------- .../doctype/payment_entry/payment_entry.py | 15 ++++++++------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 8ae4aa748a..2526f7b265 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -880,19 +880,15 @@ frappe.ui.form.on('Payment Entry', { //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.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; + } 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; allocated_positive_outstanding -= flt(row.allocated_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; + } 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; allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount)); } } diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 38a520996c..e6403fddef 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -271,16 +271,18 @@ class PaymentEntry(AccountsController): # if no payment template is used by invoice and has a custom term(no `payment_term`), then invoice outstanding will be in 'None' key latest = latest.get(d.payment_term) or latest.get(None) - # The reference has already been fully paid if not latest: frappe.throw( _("{0} {1} has already been fully paid.").format(_(d.reference_doctype), d.reference_name) ) # The reference has already been partly paid - elif latest.outstanding_amount < latest.invoice_amount and flt( - d.outstanding_amount, d.precision("outstanding_amount") - ) != flt(latest.outstanding_amount, d.precision("outstanding_amount")): + elif ( + latest.outstanding_amount < latest.invoice_amount + and flt(d.outstanding_amount, d.precision("outstanding_amount")) + != flt(latest.outstanding_amount, d.precision("outstanding_amount")) + and d.payment_term == "" + ): frappe.throw( _( "{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' or the 'Get Outstanding Orders' button to get the latest outstanding amounts." @@ -1751,11 +1753,10 @@ def split_invoices_based_on_payment_terms(outstanding_invoices, company): "voucher_type": d.voucher_type, "posting_date": d.posting_date, "invoice_amount": flt(d.invoice_amount), - "outstanding_amount": flt(d.outstanding_amount), - "payment_term_outstanding": payment_term_outstanding, - "allocated_amount": payment_term_outstanding + "outstanding_amount": payment_term_outstanding if payment_term_outstanding else d.outstanding_amount, + "payment_term_outstanding": payment_term_outstanding, "payment_amount": payment_term.payment_amount, "payment_term": payment_term.payment_term, "account": d.account, From 545f2ccdf1a66ccdcea04de532e637fa502b7e67 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sat, 23 Sep 2023 14:59:12 +0530 Subject: [PATCH 3/3] chore: remove unused variable --- erpnext/accounts/doctype/payment_entry/payment_entry.js | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 2526f7b265..0203c45058 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -874,7 +874,6 @@ 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