update
This commit is contained in:
+39
-29
@@ -42,16 +42,15 @@ class Loan(db.Model):
|
||||
back_populates="loans",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_all_loans(cls, customer_id=None, account_id=None, status=None, offer_id=None,
|
||||
def get_all_loans(cls, id=None, customer_id=None, account_id=None, status=None, offer_id=None,
|
||||
product_id=None, start_date=None, end_date=None, due_before=None, due_after=None,
|
||||
page=1, limit=20):
|
||||
transaction_id=None, original_transaction=None, page=1, limit=20):
|
||||
"""
|
||||
Get all loans with optional filtering
|
||||
|
||||
Args:
|
||||
id (int, optional): Filter by loan ID
|
||||
customer_id (str, optional): Filter by customer ID
|
||||
account_id (str, optional): Filter by account ID
|
||||
status (str, optional): Filter by loan status
|
||||
@@ -61,6 +60,8 @@ class Loan(db.Model):
|
||||
end_date (datetime, optional): Filter by end date (created_at)
|
||||
due_before (datetime, optional): Filter loans due before this date
|
||||
due_after (datetime, optional): Filter loans due after this date
|
||||
transaction_id (str, optional): Filter by transaction ID
|
||||
original_transaction (str, optional): Filter by original transaction
|
||||
|
||||
Returns:
|
||||
list: List of Loan objects
|
||||
@@ -68,6 +69,9 @@ 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 customer_id:
|
||||
query = query.filter(cls.customer_id == customer_id)
|
||||
|
||||
@@ -83,6 +87,12 @@ class Loan(db.Model):
|
||||
if product_id:
|
||||
query = query.filter(cls.product_id == product_id)
|
||||
|
||||
if transaction_id:
|
||||
query = query.filter(cls.transaction_id == transaction_id)
|
||||
|
||||
if original_transaction:
|
||||
query = query.filter(cls.original_transaction == original_transaction)
|
||||
|
||||
if start_date:
|
||||
query = query.filter(cls.created_at >= start_date)
|
||||
|
||||
@@ -106,31 +116,31 @@ class Loan(db.Model):
|
||||
query = query.limit(limit).offset(offset)
|
||||
|
||||
return query.all(), total_count
|
||||
#
|
||||
# def to_dict(self):
|
||||
# """
|
||||
# Convert the Loan object to a dictionary format for JSON serialization.
|
||||
# """
|
||||
# return {
|
||||
# 'id': self.id,
|
||||
# 'customer_id': self.customer_id,
|
||||
# 'account_id': self.account_id,
|
||||
# 'transaction_id': self.transaction_id,
|
||||
# 'original_transaction': self.original_transaction,
|
||||
# 'offer_id': self.offer_id,
|
||||
# 'initial_loan_amount': self.initial_loan_amount,
|
||||
# 'current_loan_amount': self.current_loan_amount,
|
||||
# 'status': self.status,
|
||||
# 'product_id': self.product_id,
|
||||
# 'default_penalty_fee': self.default_penalty_fee,
|
||||
# 'continuous_fee': self.continuous_fee,
|
||||
# 'upfront_fee': self.upfront_fee,
|
||||
# 'repayment_amount': self.repayment_amount,
|
||||
# 'installment_amount': self.installment_amount,
|
||||
# 'due_date': self.due_date.isoformat() if self.due_date else None,
|
||||
# 'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||
# 'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||
# }
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
Convert the Loan object to a dictionary format for JSON serialization.
|
||||
"""
|
||||
return {
|
||||
'id': self.id,
|
||||
'customer_id': self.customer_id,
|
||||
'account_id': self.account_id,
|
||||
'transaction_id': self.transaction_id,
|
||||
'original_transaction': self.original_transaction,
|
||||
'offer_id': self.offer_id,
|
||||
'initial_loan_amount': self.initial_loan_amount,
|
||||
'current_loan_amount': self.current_loan_amount,
|
||||
'status': self.status,
|
||||
'product_id': self.product_id,
|
||||
'default_penalty_fee': self.default_penalty_fee,
|
||||
'continuous_fee': self.continuous_fee,
|
||||
'upfront_fee': self.upfront_fee,
|
||||
'repayment_amount': self.repayment_amount,
|
||||
'installment_amount': self.installment_amount,
|
||||
'due_date': self.due_date.isoformat() if self.due_date else None,
|
||||
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Loan {self.id}>'
|
||||
Reference in New Issue
Block a user