[add]: loan status

This commit is contained in:
VivianDee
2025-04-11 00:02:35 +01:00
parent d397c834f4
commit 9f9512b060
3 changed files with 50 additions and 14 deletions
+18
View File
@@ -20,6 +20,13 @@ class Customer(db.Model):
back_populates="customer",
)
loans = relationship(
"Loan",
primaryjoin="Customer.id == Loan.customer_id",
foreign_keys="Loan.customer_id",
back_populates="customer",
)
@classmethod
def is_valid_customer(cls, customer_id):
customer = cls.query.filter_by(id=customer_id).first()
@@ -47,6 +54,17 @@ class Customer(db.Model):
except IntegrityError as err:
raise ValueError(f"Database integrity error: {err}")
return customer
@classmethod
def get_customer(cls, customer_id):
"""
Get customer by ID.
"""
customer = cls.query.filter_by(id=customer_id).first()
if not customer:
raise ValueError(f"Customer does not exist")
return customer
def __repr__(self):
return f'<Customer {self.id}>'