mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-09-30 11:12:35 +02:00
Edward's diagnosis was exact: the manual /print-queue/ POST extracts filament requirements from the 3MF and writes required_filament_types + filament_overrides + ams_mapping onto the queue item, but the VP queue-mode write path skipped all of that. Net effect: scheduler reached its model-only-matching fallback and auto-dispatched onto whatever printer was free regardless of loaded colour. Extract the scheduler's existing _get_filament_requirements 3MF parser into a shared helper so the VP path can reuse it. VP's _add_to_print_queue now populates required_filament_types unconditionally (cheap; helps the scheduler reject obvious type mismatches) and writes filament_overrides with force_color_match: true per consumed slot when a new per-VP queue_force_color_match toggle is on. Default off to preserve current behaviour for upgraders. UI: new toggle on VirtualPrinterCard, mode-gated to print_queue, mirroring the existing auto-dispatch toggle. i18n: en + de translated, other 6 locales seeded with English copy. Schema: one nullable column on virtual_printers (queue_force_color_match BOOLEAN, default 0/FALSE). 11 new backend tests (8 for the extracted parser, 3 for the VP write path) + 6 new frontend tests (toggle render gating, default state, click posts queue_force_color_match in update body). Existing scheduler tests pass against the refactored helper. README, CHANGELOG, website features page, and wiki virtual-printer page all updated.
40 lines
2.1 KiB
Python
40 lines
2.1 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from backend.app.core.database import Base
|
|
|
|
|
|
class VirtualPrinter(Base):
|
|
"""Virtual printer configuration for multi-instance support."""
|
|
|
|
__tablename__ = "virtual_printers"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(100), default="Bambuddy")
|
|
enabled: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
mode: Mapped[str] = mapped_column(String(20), default="immediate") # immediate|review|print_queue|proxy
|
|
auto_dispatch: Mapped[bool] = mapped_column(
|
|
Boolean, server_default="true"
|
|
) # print_queue mode: auto-start or manual
|
|
queue_force_color_match: Mapped[bool] = mapped_column(
|
|
Boolean, server_default="false"
|
|
) # print_queue mode: pin per-slot type+color from the 3MF onto the queue
|
|
# item so the scheduler refuses to dispatch onto a printer with the wrong
|
|
# filament loaded (#1188).
|
|
model: Mapped[str | None] = mapped_column(String(50), nullable=True) # SSDP model code (server mode)
|
|
access_code: Mapped[str | None] = mapped_column(String(8), nullable=True) # 8 chars (server mode)
|
|
target_printer_id: Mapped[int | None] = mapped_column(
|
|
Integer, ForeignKey("printers.id", ondelete="SET NULL"), nullable=True
|
|
) # proxy mode
|
|
bind_ip: Mapped[str | None] = mapped_column(String(45), nullable=True) # dedicated IP (proxy mode)
|
|
remote_interface_ip: Mapped[str | None] = mapped_column(String(45), nullable=True) # SSDP advertise IP
|
|
tailscale_disabled: Mapped[bool] = mapped_column(
|
|
Boolean, server_default="true"
|
|
) # opt-in: user must explicitly enable; auto-detect only runs then
|
|
serial_suffix: Mapped[str] = mapped_column(String(9), default="391800001") # unique per printer
|
|
position: Mapped[int] = mapped_column(Integer, default=0)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
|