T025: Add ProjectEquipmentGroup, ProjectEquipment, ProjectCrew models and migration
This commit is contained in:
@@ -60,6 +60,9 @@ class Project(Base):
|
||||
function_groups: Mapped[list["ProjectFunctionGroup"]] = relationship(
|
||||
"ProjectFunctionGroup", back_populates="project", cascade="all, delete-orphan"
|
||||
)
|
||||
equipment_groups: Mapped[list["ProjectEquipmentGroup"]] = relationship(
|
||||
"ProjectEquipmentGroup", back_populates="project", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Project {self.name} ({self.status})>"
|
||||
@@ -147,6 +150,99 @@ class ProjectFunction(Base):
|
||||
function_group: Mapped["ProjectFunctionGroup"] = relationship(
|
||||
"ProjectFunctionGroup", back_populates="functions"
|
||||
)
|
||||
crew_assignments: Mapped[list["ProjectCrew"]] = relationship(
|
||||
"ProjectCrew", back_populates="project_function", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<ProjectFunction {self.name} x{self.quantity}>"
|
||||
|
||||
|
||||
class ProjectEquipmentGroup(Base):
|
||||
"""Groups project equipment under a project."""
|
||||
|
||||
__tablename__ = "project_equipment_groups"
|
||||
|
||||
id: Mapped[str] = mapped_column(
|
||||
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
project_id: Mapped[str] = mapped_column(
|
||||
String(36), ForeignKey("projects.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
start_date: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
end_date: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
# Relationships
|
||||
project: Mapped["Project"] = relationship("Project", back_populates="equipment_groups")
|
||||
items: Mapped[list["ProjectEquipment"]] = relationship(
|
||||
"ProjectEquipment", back_populates="group", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<ProjectEquipmentGroup {self.name}>"
|
||||
|
||||
|
||||
class ProjectEquipment(Base):
|
||||
"""Single equipment item within a project equipment group."""
|
||||
|
||||
__tablename__ = "project_equipment"
|
||||
|
||||
id: Mapped[str] = mapped_column(
|
||||
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
|
||||
)
|
||||
project_equipment_group_id: Mapped[str] = mapped_column(
|
||||
String(36),
|
||||
ForeignKey("project_equipment_groups.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
)
|
||||
equipment_id: Mapped[str | None] = mapped_column(
|
||||
String(36), ForeignKey("equipment.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
quantity: Mapped[float] = mapped_column(Float, nullable=False, default=1.0)
|
||||
price: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
|
||||
discount: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
|
||||
# Relationships
|
||||
group: Mapped["ProjectEquipmentGroup"] = relationship(
|
||||
"ProjectEquipmentGroup", back_populates="items"
|
||||
)
|
||||
equipment: Mapped[Optional["Equipment"]] = relationship(
|
||||
"Equipment", foreign_keys=[equipment_id]
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<ProjectEquipment {self.name} x{self.quantity}>"
|
||||
|
||||
|
||||
class ProjectCrew(Base):
|
||||
"""Crew assignment to a project function."""
|
||||
|
||||
__tablename__ = "project_crew"
|
||||
|
||||
id: Mapped[str] = mapped_column(
|
||||
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
|
||||
)
|
||||
project_function_id: Mapped[str] = mapped_column(
|
||||
String(36),
|
||||
ForeignKey("project_functions.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
)
|
||||
crew_id: Mapped[str] = mapped_column(
|
||||
String(36), ForeignKey("crew.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
start_date: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
end_date: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
# Relationships
|
||||
project_function: Mapped["ProjectFunction"] = relationship(
|
||||
"ProjectFunction", back_populates="crew_assignments"
|
||||
)
|
||||
crew_member: Mapped["Crew"] = relationship("Crew")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<ProjectCrew {self.crew_id} -> {self.project_function_id}>"
|
||||
|
||||
Reference in New Issue
Block a user