[add]: Loan repayment event

This commit is contained in:
VivianDee
2025-04-10 17:15:19 +01:00
parent 6f15ae97f4
commit f252e33be2
5 changed files with 39 additions and 19 deletions
+15 -10
View File
@@ -2,6 +2,7 @@ from datetime import datetime, timezone
from sqlalchemy.orm import relationship
from app.extensions import db
from app.models.account import Account
from sqlalchemy.exc import IntegrityError
class Customer(db.Model):
__tablename__ = 'customers'
@@ -33,16 +34,20 @@ class Customer(db.Model):
# Create the customer
customer = cls(id=id, msisdn=msisdn, country_code=country_code)
db.session.add(customer)
# Create an associated account
account = Account.create_account(
id=account_id,
customer_id=id,
account_type=account_type
)
db.session.commit()
try:
db.session.add(customer)
# Create an associated account
account = Account.create_account(
id=account_id,
customer_id=id,
account_type=account_type
)
db.session.commit()
except IntegrityError as err:
db.session.rollback()
raise ValueError(f"Database integrity error: {err}")
return customer
def __repr__(self):