[add]: loan total amount

This commit was merged in pull request #29.
This commit is contained in:
VivianDee
2025-06-20 15:58:53 +01:00
parent 3cf6c94786
commit c550c8c356
2 changed files with 12 additions and 4 deletions
+11 -3
View File
@@ -223,10 +223,18 @@ class Loan(db.Model):
@classmethod
def get_customer_loans(cls, customer_id):
"""
Get customer's active loans by customer_id.
Get customer's active loans and sum by customer_id.
"""
customer_loans = cls.query.filter_by( customer_id = customer_id).all()
if not customer_loans:
raise ValueError(f"Customer with Id {customer_id} does not have any loan.")
logger.info(f"Found {len(customer_loans)} loans for customer ID: {customer_id}")
return customer_loans
total_amount = (
db.session.query(func.coalesce(func.sum(cls.current_loan_amount), 0.0))
.filter_by(customer_id=customer_id)
.scalar()
)
logger.info(f"Found {len(customer_loans)} loans for customer ID: {customer_id} with total amount: {total_amount}")
return customer_loans, total_amount
+1 -1
View File
@@ -154,7 +154,7 @@ def salary_detect():
# Step 3.2: Get loans
try:
loans = LoanService.get_customer_loans(pending_salary.customer_id)
loans, total_amount = LoanService.get_customer_loans(pending_salary.customer_id)
if not loans:
logger.warning(f"No loans found for customer ID: {pending_salary.customer_id}")
continue