mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-22 03:49:18 +02:00
fix: resolve printer model server-side for "Any Model" queue items (#435)
The previous fix passed target_model from the frontend, but this relied on printer.model being set on the client. When a printer was added without selecting a model (the field is optional), the frontend sent no target_model parameter, causing the OR logic to be bypassed entirely — the widget only queried printer_id=X and missed unassigned model-based items. The backend now looks up the printer's model from the database when target_model isn't provided by the client, ensuring "Clear Plate & Start Next" appears for model-based queue jobs regardless of how the printer was configured.
This commit is contained in:
@@ -270,19 +270,30 @@ async def list_queue(
|
||||
if printer_id == -1:
|
||||
# Special value: filter for unassigned items
|
||||
query = query.where(PrintQueueItem.printer_id.is_(None))
|
||||
elif target_model:
|
||||
# Include both printer-specific items AND model-based (unassigned) items
|
||||
query = query.where(
|
||||
or_(
|
||||
PrintQueueItem.printer_id == printer_id,
|
||||
and_(
|
||||
PrintQueueItem.printer_id.is_(None),
|
||||
func.lower(PrintQueueItem.target_model) == target_model.lower(),
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
query = query.where(PrintQueueItem.printer_id == printer_id)
|
||||
# Resolve effective model: prefer explicit param, fall back to printer's DB model.
|
||||
# This ensures model-based "Any X" items are returned even when the frontend
|
||||
# doesn't send target_model (e.g. printer.model is NULL on the client side).
|
||||
effective_model = target_model
|
||||
if not effective_model:
|
||||
printer_row = (
|
||||
await db.execute(select(Printer.model).where(Printer.id == printer_id))
|
||||
).scalar_one_or_none()
|
||||
effective_model = printer_row
|
||||
|
||||
if effective_model:
|
||||
# Include both printer-specific items AND model-based (unassigned) items
|
||||
query = query.where(
|
||||
or_(
|
||||
PrintQueueItem.printer_id == printer_id,
|
||||
and_(
|
||||
PrintQueueItem.printer_id.is_(None),
|
||||
func.lower(PrintQueueItem.target_model) == effective_model.lower(),
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
query = query.where(PrintQueueItem.printer_id == printer_id)
|
||||
elif target_model:
|
||||
query = query.where(func.lower(PrintQueueItem.target_model) == target_model.lower())
|
||||
if status:
|
||||
|
||||
Reference in New Issue
Block a user