get recent loans
This commit is contained in:
+38
-35
@@ -55,7 +55,7 @@ class Loan(db.Model):
|
||||
@classmethod
|
||||
def get_all_loans(cls, id=None, customer_id=None, account_id=None, status=None, tenor=None, offer_id=None,
|
||||
product_id=None, start_date=None, end_date=None, due_before=None, due_after=None,
|
||||
transaction_id=None, original_transaction=None, page=1, limit=20):
|
||||
transaction_id=None, original_transaction=None, page=1, limit=20, recent_only= False):
|
||||
"""
|
||||
Get all loans with optional filtering
|
||||
|
||||
@@ -79,55 +79,58 @@ class Loan(db.Model):
|
||||
"""
|
||||
query = cls.query
|
||||
logger.info(f"Get all loan models from loans model cme back")
|
||||
# Apply filters if provided
|
||||
if id:
|
||||
query = query.filter(cls.id == id)
|
||||
if recent_only:
|
||||
query = query.order_by(cls.created_at.desc()).limit(10)
|
||||
else:
|
||||
# Apply filters if provided
|
||||
if id:
|
||||
query = query.filter(cls.id == id)
|
||||
|
||||
if customer_id:
|
||||
query = query.filter(cls.customer_id == customer_id)
|
||||
if customer_id:
|
||||
query = query.filter(cls.customer_id == customer_id)
|
||||
|
||||
if account_id:
|
||||
query = query.filter(cls.account_id == account_id)
|
||||
if account_id:
|
||||
query = query.filter(cls.account_id == account_id)
|
||||
|
||||
if status:
|
||||
query = query.filter(cls.status == status)
|
||||
if status:
|
||||
query = query.filter(cls.status == status)
|
||||
|
||||
if tenor:
|
||||
query = query.filter(cls.tenor == tenor)
|
||||
if tenor:
|
||||
query = query.filter(cls.tenor == tenor)
|
||||
|
||||
if offer_id:
|
||||
query = query.filter(cls.offer_id == offer_id)
|
||||
if offer_id:
|
||||
query = query.filter(cls.offer_id == offer_id)
|
||||
|
||||
if product_id:
|
||||
query = query.filter(cls.product_id == product_id)
|
||||
if product_id:
|
||||
query = query.filter(cls.product_id == product_id)
|
||||
|
||||
if transaction_id:
|
||||
query = query.filter(cls.transaction_id == transaction_id)
|
||||
if transaction_id:
|
||||
query = query.filter(cls.transaction_id == transaction_id)
|
||||
|
||||
if original_transaction:
|
||||
query = query.filter(cls.original_transaction == original_transaction)
|
||||
if original_transaction:
|
||||
query = query.filter(cls.original_transaction == original_transaction)
|
||||
|
||||
if start_date:
|
||||
query = query.filter(cls.created_at >= start_date)
|
||||
if start_date:
|
||||
query = query.filter(cls.created_at >= start_date)
|
||||
|
||||
if end_date:
|
||||
query = query.filter(cls.created_at <= end_date)
|
||||
if end_date:
|
||||
query = query.filter(cls.created_at <= end_date)
|
||||
|
||||
if due_before:
|
||||
query = query.filter(cls.due_date <= due_before)
|
||||
if due_before:
|
||||
query = query.filter(cls.due_date <= due_before)
|
||||
|
||||
if due_after:
|
||||
query = query.filter(cls.due_date >= due_after)
|
||||
if due_after:
|
||||
query = query.filter(cls.due_date >= due_after)
|
||||
|
||||
# Order by created_at descending (newest first)
|
||||
query = query.order_by(cls.created_at.desc())
|
||||
# Order by created_at descending (newest first)
|
||||
query = query.order_by(cls.created_at.desc())
|
||||
|
||||
# Get total count before pagination
|
||||
total_count = query.count()
|
||||
# Get total count before pagination
|
||||
total_count = query.count()
|
||||
|
||||
# Apply pagination
|
||||
offset = (page - 1) * limit
|
||||
query = query.limit(limit).offset(offset)
|
||||
# Apply pagination
|
||||
offset = (page - 1) * limit
|
||||
query = query.limit(limit).offset(offset)
|
||||
|
||||
return query.all(), total_count
|
||||
|
||||
|
||||
Reference in New Issue
Block a user