added repayment_schedule

This commit is contained in:
Chinenye Nmoh
2025-08-27 12:00:42 +01:00
parent 524836f52a
commit fb460471fb
9 changed files with 330 additions and 131 deletions
+7 -2
View File
@@ -310,7 +310,7 @@ class Loan(db.Model):
if not loan:
raise ValueError(f"Loan with ID {loan_id} does not exist.")
# Convert to Decimal and round to 2 decimal places
amount_collected = Decimal(str(amount_collected)).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
balance = Decimal(str(loan.balance or 0)).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
@@ -321,7 +321,12 @@ class Loan(db.Model):
if balance <= Decimal("0.00"):
raise ValueError("There is no balance for this loan.")
if amount_collected > balance:
raise ValueError("Repayment amount exceeds current loan balance.")
# allow tiny rounding diff
if abs(amount_collected - balance) <= Decimal("0.01"):
amount_collected = balance
else:
raise ValueError("Repayment amount exceeds current loan balance.")
# Deduct the amount from the current balance
new_balance = balance - amount_collected