""" KPI 審核紀錄 Model """ from datetime import datetime from typing import Optional, TYPE_CHECKING from sqlalchemy import String, Integer, DateTime, Text, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from app.core.database import Base if TYPE_CHECKING: from app.models.kpi_sheet import KPISheet from app.models.employee import Employee class KPIReviewLog(Base): """KPI 審核紀錄""" __tablename__ = "KPI_D_review_logs" id: Mapped[int] = mapped_column(primary_key=True) sheet_id: Mapped[int] = mapped_column(ForeignKey("KPI_D_sheets.id", ondelete="CASCADE"), nullable=False) action: Mapped[str] = mapped_column(String(50), nullable=False) # submit, approve, reject, self_eval, manager_eval actor_id: Mapped[int] = mapped_column(ForeignKey("KPI_D_employees.id"), nullable=False) from_status: Mapped[Optional[str]] = mapped_column(String(20)) to_status: Mapped[Optional[str]] = mapped_column(String(20)) comment: Mapped[Optional[str]] = mapped_column(Text) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow) # Relationships sheet: Mapped["KPISheet"] = relationship("KPISheet", back_populates="review_logs") actor: Mapped["Employee"] = relationship("Employee") def __repr__(self) -> str: return f""