Description
Advance Payment validation for Term Loans fails when no corresponding Loan Repayment Schedule exists for the loan.
The validation logic fetches monthly_repayment_amount using frappe.db.get_value(). When no matching repayment schedule is found, the method returns None, which later causes invalid numeric comparisons during validation.
Steps to Reproduce
-
Create a Term Loan with is_term_loan = 1
-
Ensure no active Loan Repayment Schedule exists for the loan
-
Create a Loan Repayment entry with:
repayment_type = "Advance Payment"
-
Enter any repayment amount
-
Save or submit the document
Actual Behavior
Validation fails because monthly_repayment_amount becomes None.
Error Screenshot
Traceback
TypeError: '<' not supported between instances of 'float' and 'NoneType'
Expected Behavior
Validation should safely handle cases where no Loan Repayment Schedule exists.
The system should:
- treat missing values safely as numeric values
- avoid
NoneType comparison issues
- continue validation without unexpected failure
Root Cause
frappe.db.get_value() returns None when no matching record exists.
Current implementation:
monthly_repayment_amount = frappe.db.get_value(
"Loan Repayment Schedule",
filters,
"monthly_repayment_amount",
)
This later results in comparisons like:
amount_paid < monthly_repayment_amount
where monthly_repayment_amount is None.
Proposed Fix
Safely cast the fetched value using flt().
monthly_repayment_amount = flt(
frappe.db.get_value(
"Loan Repayment Schedule",
filters,
"monthly_repayment_amount",
),
precision
)
Also normalize amount_paid before comparison:
amount_paid = flt(amount_paid, precision)
Module
Loan Management
Version
- ERPNext: 17.x.x-develop (develop)
- Frappe Framework: 17.x.x-develop (develop)
- Lending: 0.0.1 (develop)
Installation method
None
Relevant log output / Stack trace / Full Error Message.
Code of Conduct
Description
Advance Payment validation for Term Loans fails when no corresponding
Loan Repayment Scheduleexists for the loan.The validation logic fetches
monthly_repayment_amountusingfrappe.db.get_value(). When no matching repayment schedule is found, the method returnsNone, which later causes invalid numeric comparisons during validation.Steps to Reproduce
Create a Term Loan with
is_term_loan = 1Ensure no active
Loan Repayment Scheduleexists for the loanCreate a Loan Repayment entry with:
repayment_type = "Advance Payment"Enter any repayment amount
Save or submit the document
Actual Behavior
Validation fails because
monthly_repayment_amountbecomesNone.Error Screenshot
Traceback
Expected Behavior
Validation should safely handle cases where no
Loan Repayment Scheduleexists.The system should:
NoneTypecomparison issuesRoot Cause
frappe.db.get_value()returnsNonewhen no matching record exists.Current implementation:
This later results in comparisons like:
where
monthly_repayment_amountisNone.Proposed Fix
Safely cast the fetched value using
flt().Also normalize
amount_paidbefore comparison:Module
Loan Management
Version
Installation method
None
Relevant log output / Stack trace / Full Error Message.
Code of Conduct