[update]: model class methods
This commit is contained in:
@@ -22,6 +22,15 @@ class Account(db.Model):
|
||||
# viewonly=True
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def is_valid_account(cls, account_id, customer_id):
|
||||
account = cls.query.filter_by(id=account_id, customer_id=customer_id).first()
|
||||
if not account:
|
||||
return False, "Account not found or doesn't belong to customer"
|
||||
if account.lien_amount > 0:
|
||||
return False, "Account has an existing lien"
|
||||
return True, "Account is valid"
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Account {self.id}>'
|
||||
|
||||
@@ -11,6 +11,13 @@ class Customer(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 is_eligible(cls, customer_id):
|
||||
customer = cls.query.filter_by(id=customer_id).first()
|
||||
if not customer:
|
||||
return False, "Customer not found"
|
||||
return True, "Customer is eligible"
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Customer {self.id}>'
|
||||
return f'<Customer {self.id}>'
|
||||
|
||||
|
||||
@@ -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}>'
|
||||
Reference in New Issue
Block a user