[add]: Lona repayment schedule

This commit is contained in:
Vivian Dee
2025-04-25 14:29:13 +01:00
parent 0995f08aea
commit c216c55928
5 changed files with 106 additions and 14 deletions
+11 -1
View File
@@ -5,6 +5,9 @@ from app.models.account import Account
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import relationship
from app.models.loan_charge import LoanCharge
from dateutil.relativedelta import relativedelta
from app.models.loan_repayment_schedule import LoanRepaymentSchedule # Make sure this import exists
class Loan(db.Model):
@@ -47,6 +50,13 @@ class Loan(db.Model):
back_populates="loan",
)
loan_repayent_schedules = relationship(
"LoanRepaymentSchedule",
primaryjoin="Loan.id == LoanRepaymentSchedule.loan_id",
foreign_keys="LoanRepaymentSchedule.loan_id",
back_populates="loan",
)
@classmethod
def create_loan(
cls,
@@ -60,6 +70,7 @@ class Loan(db.Model):
upfront_fee,
repayment_amount,
installment_amount,
tenor,
status="pending",
):
# Check if customer exists
@@ -92,7 +103,6 @@ class Loan(db.Model):
raise ValueError(f"Database integrity error: {err}")
return loan
@classmethod
def has_active_loans(cls, customer_id):
active_loans = cls.query.filter_by(