Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1742,8 +1742,14 @@ def validate_advance_payment(self, amount_paid, amounts, on_submit):
"monthly_repayment_amount",
)

if (flt(amount_paid, precision) < monthly_repayment_amount) or (
flt(amount_paid, precision) > (2 * monthly_repayment_amount)
if not monthly_repayment_amount:
frappe.throw(_("Cannot process Advance Payment: No active Loan Repayment Schedule found for this loan"))

monthly_repayment_amount = flt(monthly_repayment_amount, precision)
amount_paid = flt(amount_paid, precision)

if (amount_paid < monthly_repayment_amount) or (
amount_paid > (2 * monthly_repayment_amount)
):
Comment thread
Hemil-Sangani marked this conversation as resolved.
frappe.throw(_("Amount for advance payment must be between one to two EMI amount"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See license.txt

import frappe
from frappe import _
from frappe.query_builder import DocType
from frappe.query_builder import functions as fn
from frappe.utils import add_days, add_months, date_diff, flt, get_datetime, getdate
Expand Down Expand Up @@ -1938,3 +1939,44 @@ def test_no_repayment_after_full_settlement_except_waivers(self):
create_repayment_entry(
loan.name, "2025-09-06", 5000, repayment_type="Normal Repayment"
)

def test_advance_payment_no_active_schedule(self):
set_loan_accrual_frequency(loan_accrual_frequency="Daily")

loan = create_loan(
"_Test Customer 1",
"Term Loan Product 4",
200000,
"Repay Over Number of Periods",
12,
repayment_start_date="2025-01-05",
posting_date="2024-12-26",
rate_of_interest=31,
applicant_type="Customer",
)
loan.submit()

make_loan_disbursement_entry(
loan.name,
loan.loan_amount,
disbursement_date="2024-12-26",
repayment_start_date="2025-01-05",
)

# Deactivate the repayment schedule to simulate no active schedule
schedule_name = frappe.db.get_value(
"Loan Repayment Schedule",
{"loan": loan.name, "docstatus": 1, "status": "Active"},
"name",
)
frappe.db.set_value("Loan Repayment Schedule", schedule_name, "status", "Closed")

with self.assertRaises(frappe.ValidationError) as ctx:
create_repayment_entry(
loan.name, "2025-01-03", paid_amount=19596, repayment_type="Advance Payment"
)

self.assertIn(
_("Cannot process Advance Payment: No active Loan Repayment Schedule found for this loan"),
str(ctx.exception),
)