init commit
This commit is contained in:
57
app/db/models/transaction.py
Normal file
57
app/db/models/transaction.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""Transaction model for income/expense records"""
|
||||
|
||||
from sqlalchemy import Column, Integer, Float, String, DateTime, Boolean, ForeignKey, Text, Enum
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from enum import Enum as PyEnum
|
||||
from app.db.database import Base
|
||||
|
||||
|
||||
class TransactionType(str, PyEnum):
|
||||
"""Types of transactions"""
|
||||
EXPENSE = "expense"
|
||||
INCOME = "income"
|
||||
TRANSFER = "transfer"
|
||||
|
||||
|
||||
class Transaction(Base):
|
||||
"""Transaction model - represents income/expense transaction"""
|
||||
|
||||
__tablename__ = "transactions"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
family_id = Column(Integer, ForeignKey("families.id"), nullable=False, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
|
||||
account_id = Column(Integer, ForeignKey("accounts.id"), nullable=False, index=True)
|
||||
category_id = Column(Integer, ForeignKey("categories.id"), nullable=True)
|
||||
|
||||
# Transaction details
|
||||
amount = Column(Float, nullable=False)
|
||||
transaction_type = Column(Enum(TransactionType), nullable=False)
|
||||
description = Column(String(500), nullable=True)
|
||||
notes = Column(Text, nullable=True)
|
||||
tags = Column(String(500), nullable=True) # Comma-separated tags
|
||||
|
||||
# Receipt
|
||||
receipt_photo_url = Column(String(500), nullable=True)
|
||||
|
||||
# Recurring transaction
|
||||
is_recurring = Column(Boolean, default=False)
|
||||
recurrence_pattern = Column(String(50), nullable=True) # daily, weekly, monthly, etc.
|
||||
|
||||
# Status
|
||||
is_confirmed = Column(Boolean, default=True)
|
||||
|
||||
# Timestamps
|
||||
transaction_date = Column(DateTime, nullable=False, index=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
family = relationship("Family")
|
||||
user = relationship("User", back_populates="transactions")
|
||||
account = relationship("Account", back_populates="transactions")
|
||||
category = relationship("Category", back_populates="transactions")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Transaction(id={self.id}, amount={self.amount}, type={self.transaction_type})>"
|
||||
Reference in New Issue
Block a user