feat: printing problems shown and handled; printing set-up on v2 (platform-v2 step 6.10)

- a ticket that doesn't print is a problem for whoever sent it and the managers:
  GET /api/print-problems (the order, table, dishes, printer, since when, tries,
  last error, who sent it) and three ways out: print again, send to another
  printer, handled (services/print_problems.py; print_jobs.resolved_by /
  redirected_to, Alembic 0036); live event print.problems from the print paths
- phone: the red printer button opens the problems sheet, the table page warns
  (usePrintProblems replaces the 8 s poll); counter POS: a red button under the
  modes with the shared panel (@xenia/ordering PrintProblemsPanel + pure rules);
  manager: a card on the overview (top), the Tables page and the order page
- manager: Settings -> Printing (printers with reachability, test print, network
  scan; ticket layout + test ticket, beep, fonts with previews, dot leader,
  dividers) and Management -> Prep zones (cards + zone dialog with the ticket
  language, printers, copies, sorting, category order, kitchen screen) rebuilt in
  src/pages/printing; v1 PrintFontsTab, PrepZonesConfigPage, PendingPrints and
  /api/orders/pending-prints removed
- access: printer add/edit/delete/scan need core.settings.manage, prep zone
  changes catalog.menu.manage (were any dashboard user)
- tests: test_print_problems.py, @xenia/ordering printProblems, manager
  printing.test.mjs, e2e print_problems.mjs (done-when) + manager.mjs printing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 01:40:07 +02:00
co-authored by Claude Opus 5.5
parent 070c9cf625
commit f31bdf42aa
57 changed files with 2557 additions and 2221 deletions
+5 -43
View File
@@ -284,49 +284,6 @@ def list_active_orders(db: Session = Depends(get_db), user: User = Depends(get_c
]
# ─── Pending print jobs count (for PWA header badge) ─────────────────────────
@router.get("/pending-prints")
def get_pending_prints(
db: Session = Depends(get_db),
user: User = Depends(get_current_user),
):
"""Returns count of pending print jobs + per-order detail for the current shift."""
pending_jobs = db.query(PrintJob).filter(PrintJob.status == "pending").all()
from collections import defaultdict
by_order: dict = defaultdict(list)
for pj in pending_jobs:
by_order[pj.order_id].append(pj)
orders_data = []
for order_id, jobs in by_order.items():
order = db.query(Order).filter(Order.id == order_id).first()
if not order or order.status in ("closed", "cancelled"):
continue
table_name = None
if order.table:
table_name = order.table.label or f"T{order.table.number}"
orders_data.append({
"order_id": order_id,
"table_name": table_name,
"opened_at": order.opened_at.isoformat() if order.opened_at else None,
"jobs": [
{
"id": pj.id,
"printer_id": pj.printer_id,
"retry_count": pj.retry_count,
"first_attempted_at": pj.first_attempted_at.isoformat() if pj.first_attempted_at else None,
"last_attempted_at": pj.last_attempted_at.isoformat() if pj.last_attempted_at else None,
"item_ids": json.loads(pj.item_ids or "[]"),
}
for pj in jobs
],
})
return {"count": len(pending_jobs), "orders": orders_data}
@router.get("/menu")
def ordering_menu(db: Session = Depends(get_db), user: User = Depends(get_current_user)):
"""What the manager's ordering offers (plan step 6.9): the categories and every product sold
@@ -900,6 +857,9 @@ def retry_print(
print_results = route_and_print_sync(order_id, unprinted_ids, db)
db.refresh(order)
if print_results and all(r.get("success") for r in print_results):
from services.print_problems import announce
announce(order_id) # 6.10: printed again, the warning clears
return {"order": order, "print_results": print_results}
@@ -1892,6 +1852,8 @@ def cancel_print_job(
logging.getLogger("services.printer_service").warning(
"print.job.abandoned job=%s order=%s attempts=%s reason=staff_cancelled", pj.id, order_id, pj.retry_count)
broadcast_sync("order_updated", {"order_id": order_id, "table_id": order.table_id, "status": order.status, "action": "print_job_cancelled"})
from services.print_problems import announce
announce(order_id)
return {"ok": True, "job_id": job_id}