Skip to content

Issue: Advance Payment validation fails when Loan Repayment Schedule is missing #1240

@Hemil-Sangani

Description

@Hemil-Sangani

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

  1. Create a Term Loan with is_term_loan = 1

  2. Ensure no active Loan Repayment Schedule exists for the loan

  3. Create a Loan Repayment entry with:

    • repayment_type = "Advance Payment"
  4. Enter any repayment amount

  5. Save or submit the document


Actual Behavior

Validation fails because monthly_repayment_amount becomes None.

Error Screenshot

Image

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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions