45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""Savings goal model"""
|
|
|
|
from sqlalchemy import Column, Integer, Float, String, DateTime, Boolean, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
from app.db.database import Base
|
|
|
|
|
|
class Goal(Base):
|
|
"""Goal model - savings goals with progress tracking"""
|
|
|
|
__tablename__ = "goals"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
family_id = Column(Integer, ForeignKey("families.id"), nullable=False, index=True)
|
|
account_id = Column(Integer, ForeignKey("accounts.id"), nullable=True)
|
|
|
|
# Goal details
|
|
name = Column(String(255), nullable=False)
|
|
description = Column(String(500), nullable=True)
|
|
target_amount = Column(Float, nullable=False)
|
|
current_amount = Column(Float, default=0.0)
|
|
|
|
# Priority
|
|
priority = Column(Integer, default=0)
|
|
|
|
# Status
|
|
is_active = Column(Boolean, default=True)
|
|
is_completed = Column(Boolean, default=False)
|
|
|
|
# Deadlines
|
|
target_date = Column(DateTime, nullable=True)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
completed_at = Column(DateTime, nullable=True)
|
|
|
|
# Relationships
|
|
family = relationship("Family", back_populates="goals")
|
|
account = relationship("Account")
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Goal(id={self.id}, name={self.name}, target={self.target_amount})>"
|