[add]: loan ref to repayment

This commit is contained in:
VivianDee
2025-05-28 20:05:38 +01:00
parent 65472d3f07
commit 729cc26698
6 changed files with 21 additions and 26 deletions
+2
View File
@@ -48,6 +48,8 @@ class Customer(db.Model):
def create_customer(cls, id, msisdn, country_code, account_id, account_type='savings'):
if cls.query.filter_by(id=id).first():
raise ValueError("Customer already exists")
elif Account.query.filter_by(id=account_id).first():
raise ValueError("Account already exists")
# Create the customer
customer = cls(
+3 -11
View File
@@ -23,15 +23,7 @@ class Repayment(db.Model):
transaction_id = db.Column(db.String(50), nullable=True)
@classmethod
def create_repayment(cls, customer_id, loan_id, product_id, transaction_id):
# Check customer exists
if not Customer.is_valid_customer(customer_id):
raise ValueError("Invalid customer")
# Check loan exists
loan = Loan.get_customer_loan(loan_id = loan_id, customer_id = customer_id)
def create_repayment(cls, customer_id, loan, transaction_id):
# Check that the loan is active
if loan.status not in [LoanStatus.ACTIVE, LoanStatus.START_REPAY]:
@@ -40,8 +32,8 @@ class Repayment(db.Model):
repayment = cls(
customer_id=customer_id,
loan_id=loan_id,
product_id=product_id,
loan_id=loan.id,
product_id=loan.product_id,
transaction_id = transaction_id,
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc)