[add]: loan total amount #29
+11
-3
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user