corrected interest charges on 3 months loan and made loan schedule active by default

This commit was merged in pull request #65.
This commit is contained in:
Chinenye Nmoh
2026-01-29 22:11:59 +01:00
parent f6f8e369c4
commit 5c8ffc5bbc
4 changed files with 49 additions and 11 deletions
+9 -3
View File
@@ -236,9 +236,15 @@ class Loan(db.Model):
"""
Get the latest loan without a disbursement date.
"""
return cls.query.filter(
cls.disburse_date.is_(None)
).order_by(cls.created_at.desc()).first()
logger.info("Fetching latest loan without disburse date")
try:
return cls.query.filter(
cls.disburse_date.is_(None)
).order_by(cls.created_at.desc()).first()
except Exception as e:
logger.error(f"Error fetching latest loan without disburse date: {e}")
raise
@classmethod
def get_latest_loan_with_disburse_date(cls):
+19 -1
View File
@@ -215,7 +215,25 @@ class LoanRepaymentSchedule(db.Model):
logger.error(f"Error updating repayment schedule {schedule_id} after loan repayment: {e}")
raise
@classmethod
def update_repayment_schedule_status_to_active(cls, schedule_id):
"""
Update repayment schedule status to ACTIVE.
"""
try:
schedule = cls.query.get(schedule_id)
if not schedule:
raise ValueError(f"Schedule with ID {schedule_id} does not exist.")
schedule.paid_status = RepaymentScheduleStatus.ACTIVE
schedule.updated_at = datetime.now(timezone.utc)
db.session.commit()
logger.info(f"Updated repayment schedule ID {schedule_id} status to ACTIVE")
return schedule.to_dict()
except Exception as e:
db.session.rollback()
logger.error(f"Error updating repayment schedule status for schedule {schedule_id}: {e}")
raise
@classmethod
def update_repayment_schedule_balance(cls, schedule_id, amount_collected):
"""