Merge branch 'add_total_amount' of DigiFi/digifi-EventManager into master

This commit is contained in:
2025-06-20 16:28:39 +00:00
committed by Gogs
2 changed files with 12 additions and 4 deletions
+11 -3
View File
@@ -223,10 +223,18 @@ class Loan(db.Model):
@classmethod @classmethod
def get_customer_loans(cls, customer_id): 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() customer_loans = cls.query.filter_by( customer_id = customer_id).all()
if not customer_loans: if not customer_loans:
raise ValueError(f"Customer with Id {customer_id} does not have any loan.") 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 # Step 3.2: Get loans
try: try:
loans = LoanService.get_customer_loans(pending_salary.customer_id) loans, total_amount = LoanService.get_customer_loans(pending_salary.customer_id)
if not loans: if not loans:
logger.warning(f"No loans found for customer ID: {pending_salary.customer_id}") logger.warning(f"No loans found for customer ID: {pending_salary.customer_id}")
continue continue