[update]: model class methods

This commit is contained in:
VivianDee
2025-03-28 10:11:44 +01:00
parent ad39b1c75c
commit bc8f8e2cdd
6 changed files with 30 additions and 33 deletions
+13
View File
@@ -15,5 +15,18 @@ class Loan(db.Model):
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
@classmethod
def has_active_loans(cls, customer_id):
active_loans = cls.query.filter_by(
customer_id=customer_id,
status='active'
).count()
if active_loans > 0:
return False, "Customer has active loans"
return True, "No active loans"
def __repr__(self):
return f'<Loan {self.id}>'