added repayment_schedule
This commit is contained in:
+7
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user