From 79109af695f12fcc1353fc1875d0c1f3e28dffc5 Mon Sep 17 00:00:00 2001 From: Chinenye Nmoh Date: Thu, 26 Jun 2025 13:36:49 +0100 Subject: [PATCH] balance --- app/models/loan.py | 4 ++-- app/routes/autocall.py | 2 +- app/services/loan.py | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/loan.py b/app/models/loan.py index 2bf0359..2c3739a 100644 --- a/app/models/loan.py +++ b/app/models/loan.py @@ -247,9 +247,9 @@ class Loan(db.Model): """ 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, status='active').all() 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 active loan.") total_amount = ( cls.query.with_entities(func.coalesce(func.sum(cls.balance), 0.0)) diff --git a/app/routes/autocall.py b/app/routes/autocall.py index a156181..a11ec43 100644 --- a/app/routes/autocall.py +++ b/app/routes/autocall.py @@ -168,7 +168,7 @@ def process_salary_list(): # Step 3.2: Get loans try: - loans, total_amount = LoanService.get_customer_loans(pending_salary.customer_id) + loans, total_amount = LoanService.get_customer_active_loans(pending_salary.customer_id) if not loans: logger.warning(f"No loans found for customer ID: {pending_salary.customer_id}") continue diff --git a/app/services/loan.py b/app/services/loan.py index 293b1be..ecf0de5 100644 --- a/app/services/loan.py +++ b/app/services/loan.py @@ -77,6 +77,13 @@ class LoanService: Get customer's active loans by customer_id. """ + return Loan.get_customer_loans(customer_id=customer_id) + @classmethod + def get_customer_active_loans(cls, customer_id): + """ + Get customer's active loans by customer_id. + """ + return Loan.get_customer_loans(customer_id=customer_id) @classmethod