Files
bambuddy/backend/app/models/print_queue.py
T
maziggyandClaude Opus 4.5 ad4e4fc3a2 Add manual AMS slot selection for prints (#76)
- ReprintModal: Dropdown to override auto-matched AMS slots
- AddToQueueModal: Collapsible filament mapping section
- Backend: Store ams_mapping in print queue, apply when print starts
- Color names in dropdowns (decoded from Bambu codes or derived from hex)
- Blue ring indicator for manually selected vs auto-matched slots
- Status indicators: green (match), yellow (type only), orange (not found)

Closes #76

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 08:37:47 +01:00

56 lines
2.3 KiB
Python

from datetime import datetime
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from backend.app.core.database import Base
class PrintQueueItem(Base):
"""Print queue item for scheduled/queued prints."""
__tablename__ = "print_queue"
id: Mapped[int] = mapped_column(primary_key=True)
# Links
printer_id: Mapped[int] = mapped_column(ForeignKey("printers.id", ondelete="CASCADE"))
archive_id: Mapped[int] = mapped_column(ForeignKey("print_archives.id", ondelete="CASCADE"))
project_id: Mapped[int | None] = mapped_column(ForeignKey("projects.id", ondelete="SET NULL"), nullable=True)
# Scheduling
position: Mapped[int] = mapped_column(Integer, default=0) # Queue order
scheduled_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) # None = ASAP
manual_start: Mapped[bool] = mapped_column(Boolean, default=False) # Requires manual trigger to start
# Conditions
require_previous_success: Mapped[bool] = mapped_column(Boolean, default=False)
# Power management
auto_off_after: Mapped[bool] = mapped_column(Boolean, default=False) # Power off printer after print
# AMS mapping: JSON array of global tray IDs for each filament slot
# Format: "[5, -1, 2, -1]" where position = slot_id-1, value = global tray ID (-1 = unused)
ams_mapping: Mapped[str | None] = mapped_column(Text, nullable=True)
# Status: pending, printing, completed, failed, skipped, cancelled
status: Mapped[str] = mapped_column(String(20), default="pending")
# Tracking
started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
completed_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
# Timestamps
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
# Relationships
printer: Mapped["Printer"] = relationship()
archive: Mapped["PrintArchive"] = relationship()
project: Mapped["Project | None"] = relationship(back_populates="queue_items")
from backend.app.models.archive import PrintArchive # noqa: E402
from backend.app.models.printer import Printer # noqa: E402
from backend.app.models.project import Project # noqa: E402