added a new penal charge endpoint
This commit is contained in:
@@ -115,7 +115,7 @@ class LoanRepaymentSchedule(db.Model):
|
||||
logger.error(f"Error fetching active overdue repayment schedules: {e}")
|
||||
return []
|
||||
@classmethod
|
||||
def get_overdue_repayment_schedule_with_grace_period(cls, grace_period_days):
|
||||
def get_overdue_repayment_schedule_with_grace_period(cls, grace_period_days, limit=None):
|
||||
"""
|
||||
Get all overdue repayment schedules that are not repaid and beyond the grace period.
|
||||
"""
|
||||
@@ -124,7 +124,7 @@ class LoanRepaymentSchedule(db.Model):
|
||||
return cls.query.filter(
|
||||
cls.due_date < grace_period_date,
|
||||
cls.paid == False
|
||||
).order_by(cls.due_date.asc()).all()
|
||||
).order_by(cls.due_date.asc()).limit(limit).all()
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching overdue repayment schedules with grace period: {e}")
|
||||
return []
|
||||
@@ -274,5 +274,25 @@ class LoanRepaymentSchedule(db.Model):
|
||||
db.session.rollback()
|
||||
logger.error(f"Error applying repayment for schedule {schedule_id}: {e}")
|
||||
raise
|
||||
@classmethod
|
||||
def update_due_process_date_and_count(cls, schedule_id):
|
||||
"""
|
||||
Update the due process date to now and increment the due process count.
|
||||
"""
|
||||
try:
|
||||
schedule = cls.query.get(schedule_id)
|
||||
if schedule.due_process_count is None:
|
||||
schedule.due_process_count = 0
|
||||
schedule.due_process_count += 1
|
||||
schedule.due_process_date = datetime.now(timezone.utc)
|
||||
schedule.updated_at = datetime.now(timezone.utc)
|
||||
|
||||
db.session.commit()
|
||||
logger.info(f"Updated due process date and count for schedule ID {schedule.id}")
|
||||
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
logger.error(f"Error updating due process date and count for schedule {schedule.id}: {e}")
|
||||
raise
|
||||
|
||||
|
||||
Reference in New Issue
Block a user