fix: split inv allocated amt on server side
(cherry picked from commit b3aa201eb5)
This commit is contained in:
@@ -864,19 +864,15 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
//If allocate payment amount checkbox is unchecked, set zero to allocate amount
|
//If allocate payment amount checkbox is unchecked, set zero to allocate amount
|
||||||
row.allocated_amount = 0;
|
row.allocated_amount = 0;
|
||||||
|
|
||||||
} else if (frappe.flags.allocate_payment_amount != 0 && (row.payment_term || !row.allocated_amount || paid_amount_change)) {
|
} else if (frappe.flags.allocate_payment_amount != 0 && (!row.allocated_amount || paid_amount_change)) {
|
||||||
if(row.payment_term)
|
if (row.outstanding_amount > 0 && allocated_positive_outstanding >= 0) {
|
||||||
outstanding_amount = row.allocated_amount;
|
row.allocated_amount = (row.outstanding_amount >= allocated_positive_outstanding) ?
|
||||||
else
|
allocated_positive_outstanding : row.outstanding_amount;
|
||||||
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);
|
allocated_positive_outstanding -= flt(row.allocated_amount);
|
||||||
|
|
||||||
} else if (outstanding_amount < 0 && allocated_negative_outstanding) {
|
} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
|
||||||
row.allocated_amount = (Math.abs(outstanding_amount) >= allocated_negative_outstanding) ?
|
row.allocated_amount = (Math.abs(row.outstanding_amount) >= allocated_negative_outstanding) ?
|
||||||
-1*allocated_negative_outstanding : outstanding_amount;
|
-1*allocated_negative_outstanding : row.outstanding_amount;
|
||||||
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
|
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,16 +227,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
|
# 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)
|
latest = latest.get(d.payment_term) or latest.get(None)
|
||||||
|
|
||||||
# The reference has already been fully paid
|
# The reference has already been fully paid
|
||||||
if not latest:
|
if not latest:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("{0} {1} has already been fully paid.").format(_(d.reference_doctype), d.reference_name)
|
_("{0} {1} has already been fully paid.").format(_(d.reference_doctype), d.reference_name)
|
||||||
)
|
)
|
||||||
# The reference has already been partly paid
|
# The reference has already been partly paid
|
||||||
elif latest.outstanding_amount < latest.invoice_amount and flt(
|
elif (
|
||||||
d.outstanding_amount, d.precision("outstanding_amount")
|
latest.outstanding_amount < latest.invoice_amount
|
||||||
) != flt(latest.outstanding_amount, d.precision("outstanding_amount")):
|
and flt(d.outstanding_amount, d.precision("outstanding_amount"))
|
||||||
|
!= flt(latest.outstanding_amount, d.precision("outstanding_amount"))
|
||||||
|
and d.payment_term == ""
|
||||||
|
):
|
||||||
frappe.throw(
|
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."
|
"{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."
|
||||||
@@ -1600,11 +1602,10 @@ def split_invoices_based_on_payment_terms(outstanding_invoices, company):
|
|||||||
"voucher_type": d.voucher_type,
|
"voucher_type": d.voucher_type,
|
||||||
"posting_date": d.posting_date,
|
"posting_date": d.posting_date,
|
||||||
"invoice_amount": flt(d.invoice_amount),
|
"invoice_amount": flt(d.invoice_amount),
|
||||||
"outstanding_amount": flt(d.outstanding_amount),
|
"outstanding_amount": payment_term_outstanding
|
||||||
"payment_term_outstanding": payment_term_outstanding,
|
|
||||||
"allocated_amount": payment_term_outstanding
|
|
||||||
if payment_term_outstanding
|
if payment_term_outstanding
|
||||||
else d.outstanding_amount,
|
else d.outstanding_amount,
|
||||||
|
"payment_term_outstanding": payment_term_outstanding,
|
||||||
"payment_amount": payment_term.payment_amount,
|
"payment_amount": payment_term.payment_amount,
|
||||||
"payment_term": payment_term.payment_term,
|
"payment_term": payment_term.payment_term,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user