- NEW: ChoreAssignmentType enum (ANY_ONE, ALL_ASSIGNED) - NEW: assignment_type field with default ANY_ONE - ANY_ONE: Only one assigned person needs to complete - ALL_ASSIGNED: All assigned people must complete - Supports new chore completion logic for multi-user assignments
50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
"""Chore model."""
|
|
from sqlalchemy import Boolean, Column, Integer, String, DateTime, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
from app.core.database import Base
|
|
import enum
|
|
|
|
class ChoreFrequency(str, enum.Enum):
|
|
"""Chore frequency options."""
|
|
ON_TRIGGER = "on_trigger"
|
|
DAILY = "daily"
|
|
WEEKLY = "weekly"
|
|
FORTNIGHTLY = "fortnightly"
|
|
MONTHLY = "monthly"
|
|
|
|
class ChoreStatus(str, enum.Enum):
|
|
"""Chore status options."""
|
|
PENDING = "pending"
|
|
IN_PROGRESS = "in_progress"
|
|
COMPLETED = "completed"
|
|
SKIPPED = "skipped"
|
|
|
|
class ChoreAssignmentType(str, enum.Enum):
|
|
"""Chore assignment type - how the chore should be completed."""
|
|
ANY_ONE = "any_one" # Only one assigned person needs to complete
|
|
ALL_ASSIGNED = "all_assigned" # All assigned people must complete
|
|
|
|
class Chore(Base):
|
|
"""Chore model."""
|
|
__tablename__ = "chores"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(200), nullable=False)
|
|
description = Column(String(500))
|
|
room = Column(String(50)) # bedroom1, bedroom2, kitchen, bathroom1, etc.
|
|
frequency = Column(SQLEnum(ChoreFrequency), nullable=False)
|
|
points = Column(Integer, default=0) # Points awarded for completing the chore
|
|
image_url = Column(String(500)) # URL to chore image
|
|
assignment_type = Column(SQLEnum(ChoreAssignmentType), default=ChoreAssignmentType.ANY_ONE) # How chore should be completed
|
|
status = Column(SQLEnum(ChoreStatus), default=ChoreStatus.PENDING)
|
|
assigned_user_id = Column(Integer, ForeignKey("users.id")) # Deprecated - use assignments instead
|
|
due_date = Column(DateTime)
|
|
completed_at = Column(DateTime)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
assigned_user = relationship("User", back_populates="chores") # Deprecated - use assignments
|
|
assignments = relationship("ChoreAssignment", back_populates="chore", cascade="all, delete-orphan")
|