init commit
This commit is contained in:
50
app/db/models/budget.py
Normal file
50
app/db/models/budget.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Budget model for budget tracking"""
|
||||
|
||||
from sqlalchemy import Column, Integer, Float, String, 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 BudgetPeriod(str, PyEnum):
|
||||
"""Budget periods"""
|
||||
DAILY = "daily"
|
||||
WEEKLY = "weekly"
|
||||
MONTHLY = "monthly"
|
||||
YEARLY = "yearly"
|
||||
|
||||
|
||||
class Budget(Base):
|
||||
"""Budget model - spending limits"""
|
||||
|
||||
__tablename__ = "budgets"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
family_id = Column(Integer, ForeignKey("families.id"), nullable=False, index=True)
|
||||
category_id = Column(Integer, ForeignKey("categories.id"), nullable=True)
|
||||
|
||||
# Budget details
|
||||
name = Column(String(255), nullable=False)
|
||||
limit_amount = Column(Float, nullable=False)
|
||||
spent_amount = Column(Float, default=0.0)
|
||||
period = Column(Enum(BudgetPeriod), default=BudgetPeriod.MONTHLY)
|
||||
|
||||
# Alert threshold (percentage)
|
||||
alert_threshold = Column(Float, default=80.0)
|
||||
|
||||
# Status
|
||||
is_active = Column(Boolean, default=True)
|
||||
|
||||
# Timestamps
|
||||
start_date = Column(DateTime, nullable=False)
|
||||
end_date = Column(DateTime, nullable=True)
|
||||
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="budgets")
|
||||
category = relationship("Category", back_populates="budgets")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Budget(id={self.id}, name={self.name}, limit={self.limit_amount})>"
|
||||
Reference in New Issue
Block a user