This commit is contained in:
Azeez Muibi
2025-04-14 11:30:28 +01:00
parent 9a9d2e4ef9
commit 89fb91e874
2 changed files with 1 additions and 52 deletions
+1 -3
View File
@@ -1,7 +1,5 @@
from .customer import Customer from .customer import Customer
from .account import Account
from .loan import Loan from .loan import Loan
from .transaction import Transaction from .transaction import Transaction
from .repayment import Repayment
__all__ = ['Customer', 'Account', 'Loan', 'Transaction', 'Repayment'] __all__ = ['Customer', 'Loan', 'Transaction']
-49
View File
@@ -1,49 +0,0 @@
from datetime import datetime, timezone
from sqlalchemy.orm import relationship
from app.extensions import db
from sqlalchemy.exc import IntegrityError
class Account(db.Model):
__tablename__ = 'accounts'
id = db.Column(db.String(50), primary_key=True)
customer_id = db.Column(db.String(50), nullable=False)
account_type = db.Column(db.String(50))
status = db.Column(db.String(20), default='active')
lien_amount = db.Column(db.Float, default=0.0)
created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc))
updated_at = db.Column(db.DateTime, default=datetime.now(timezone.utc), onupdate=datetime.now(timezone.utc))
customer = relationship(
"Customer",
primaryjoin="Customer.id == Account.customer_id",
foreign_keys=[customer_id],
back_populates="accounts",
)
@classmethod
def create_account(cls, id, customer_id, account_type, status='active'):
account = cls(
id=id,
customer_id=customer_id,
account_type=account_type
)
try:
db.session.add(account)
except IntegrityError as err:
raise ValueError(f"Database integrity error: {err}")
return account
@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
if account.lien_amount > 0:
return False
return True
def __repr__(self):
return f'<Account {self.id}>'