commited loan date

This commit was merged in pull request #18.
This commit is contained in:
Chinenye Nmoh
2025-06-03 17:14:02 +01:00
parent 2872f6c75c
commit 15e012c071
3 changed files with 47 additions and 23 deletions
+20 -10
View File
@@ -7,6 +7,7 @@ import logging
from sqlalchemy import and_, or_, not_
from sqlalchemy.sql import func
from app.utils.logger import logger
from app.extensions import db
class Loan(db.Model):
__tablename__ = "loans"
@@ -82,23 +83,32 @@ class Loan(db.Model):
def get_loan_by_transaction_id(cls, transaction_id):
return cls.query.filter_by(transaction_id=transaction_id).first()
@classmethod
def get_loan_by_debt_id(cls, debt_id):
return cls.query.filter_by(id=debt_id).first()
@classmethod
def set_disbursement_date(cls, loan_id, customer_id):
"""
Update the status of the loan with the given loan_id.
Update the disburse date of the loan with the given loan_id.
"""
# Retrieve loan
loan = cls.query.get(loan_id)
if not loan:
raise ValueError(f"Loan with ID {loan_id} does not exist.")
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
logger.info(f"What is now ======= ==== ==> : {current_time}")
# Update loan disburse_date and timestamp datetime.today().strftime('%Y-%m-%d %H:%M:%S')
loan.disburse_date = current_time # datetime.today().strftime('%Y-%m-%d %H:%M:%S')
return current_time
# Check if customer_id matches
if loan.customer_id != customer_id:
raise ValueError(f"Customer ID {customer_id} does not match the loan's customer ID.")
current_time = datetime.now()
logger.info(f"What is now ======= ==== ==> : {current_time}")
# Update loan disburse_date
loan.disburse_date = current_time
# Commit changes to database
try:
logger.info(f"Updating disburse date for loan ID {loan_id} to {current_time}")
db.session.commit()
except Exception as e:
db.session.rollback()
logger.error(f"Failed to update disburse date: {e}")
raise