[add]: balance when calculating loan total #32
+3
-2
@@ -30,6 +30,7 @@ class Loan(db.Model):
|
||||
continuous_fee = db.Column(db.Float, default=0)
|
||||
upfront_fee = db.Column(db.Float, nullable=True, default=0.0)
|
||||
repayment_amount = db.Column(db.Float, nullable=True, default=0.0)
|
||||
balance = db.Column(db.Float, nullable=True, default=0.0)
|
||||
installment_amount = db.Column(db.Float, nullable=True, default=0.0)
|
||||
status = db.Column(db.String(20), default='pending')
|
||||
tenor = db.Column(db.Integer, nullable=True)
|
||||
@@ -230,10 +231,10 @@ class Loan(db.Model):
|
||||
raise ValueError(f"Customer with Id {customer_id} does not have any loan.")
|
||||
|
||||
total_amount = (
|
||||
db.session.query(func.coalesce(func.sum(cls.current_loan_amount), 0.0))
|
||||
cls.query.with_entities(func.coalesce(func.sum(cls.balance), 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}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user