[add]: loan_repayment event

This commit is contained in:
VivianDee
2025-04-10 17:02:54 +01:00
parent edd19b9a39
commit 7cea5390c0
7 changed files with 101 additions and 33 deletions
+10
View File
@@ -26,6 +26,16 @@ class Loan(db.Model):
return False, "Customer has active loans"
return True, "No active loans"
@classmethod
def get_customer_loan(cls, loan_id, customer_id):
"""
Check if a loan with the given ID exists and if the loan belongs to the specified customer_id.
"""
loan = cls.query.filter_by(id=loan_id, customer_id=customer_id).first()
if not loan:
raise ValueError(f"Loan with ID {loan_id} does not exist or does not belong to customer {customer_id}.")
return loan
def __repr__(self):
return f'<Loan {self.id}>'