"""Approval state of the company forms that carry an Area Business Manager signature.""" import uuid from datetime import datetime from sqlalchemy import DateTime, ForeignKey, String, func from sqlalchemy.dialects.postgresql import UUID as PGUUID from sqlalchemy.orm import Mapped, mapped_column from app.database.base import Base #: draft = not sent yet, pending = the MR asked for approval, approved = the Area Business Manager signed. FORM_APPROVAL_STATUSES = ("draft", "pending", "approved") class FormApproval(Base): """One row per (approval form, MR): each MR's tour plan, standard tour plan and fare chart is approved on its own.""" __tablename__ = "form_approval" table_name: Mapped[str] = mapped_column(String(64), primary_key=True) #: The MR whose rows these are. owner_user_id: Mapped[uuid.UUID] = mapped_column( PGUUID(as_uuid=True), ForeignKey("user.id", ondelete="CASCADE"), primary_key=True ) status: Mapped[str] = mapped_column(String(10), nullable=False, default="draft", server_default="draft") requested_by_user_id: Mapped[uuid.UUID | None] = mapped_column( PGUUID(as_uuid=True), ForeignKey("user.id", ondelete="SET NULL") ) approved_by_user_id: Mapped[uuid.UUID | None] = mapped_column( PGUUID(as_uuid=True), ForeignKey("user.id", ondelete="SET NULL") ) #: The name printed on the PDF. A snapshot, so renaming the user never rewrites a signature. approved_by_name: Mapped[str | None] = mapped_column(String(200)) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False )