diff --git a/app/routes/autocall.py b/app/routes/autocall.py index 0ceb155..46492ef 100644 --- a/app/routes/autocall.py +++ b/app/routes/autocall.py @@ -291,6 +291,15 @@ def process_overdue_loan(loan): if not full_loan_data: logger.warning(f"Full Loan ID {loan.loan_id} not found in database") else: + #lets check if the loan with the repayment has been repaid, then update the loan schedule to paid + if full_loan_data.to_dict().get("status") == LoanStatus.REPAID and full_loan_data.to_dict().get("balance") == 0: + try: + LoanRepaymentScheduleService.update_repayment_schedule_status(loan.id, paid=True) + logger.info(f"Updated Loan Repayment Schedule ID {loan.id} to PAID") + return + except Exception as e: + db.session.rollback() + logger.error(f"Failed to update Loan Repayment Schedule ID {loan.id} to PAID: {e}") customer_id = full_loan_data.to_dict().get("customerId") loan_status = full_loan_data.to_dict().get("status")