init commit
This commit is contained in:
50
app/db/models/account.py
Normal file
50
app/db/models/account.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Account (wallet) model"""
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Float, DateTime, Boolean, ForeignKey, Enum
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from enum import Enum as PyEnum
|
||||
from app.db.database import Base
|
||||
|
||||
|
||||
class AccountType(str, PyEnum):
|
||||
"""Types of accounts"""
|
||||
CARD = "card"
|
||||
CASH = "cash"
|
||||
DEPOSIT = "deposit"
|
||||
GOAL = "goal"
|
||||
OTHER = "other"
|
||||
|
||||
|
||||
class Account(Base):
|
||||
"""Account model - represents a user's wallet or account"""
|
||||
|
||||
__tablename__ = "accounts"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
family_id = Column(Integer, ForeignKey("families.id"), nullable=False, index=True)
|
||||
owner_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
|
||||
|
||||
name = Column(String(255), nullable=False)
|
||||
account_type = Column(Enum(AccountType), default=AccountType.CARD)
|
||||
description = Column(String(500), nullable=True)
|
||||
|
||||
# Balance
|
||||
balance = Column(Float, default=0.0)
|
||||
initial_balance = Column(Float, default=0.0)
|
||||
|
||||
# Status
|
||||
is_active = Column(Boolean, default=True)
|
||||
is_archived = Column(Boolean, default=False)
|
||||
|
||||
# Timestamps
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
family = relationship("Family", back_populates="accounts")
|
||||
owner = relationship("User", back_populates="accounts")
|
||||
transactions = relationship("Transaction", back_populates="account")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Account(id={self.id}, name={self.name}, balance={self.balance})>"
|
||||
Reference in New Issue
Block a user