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
@@ -22,7 +22,8 @@ import DaySummaryDialog from './DaySummaryDialog'
import MessagesCard, { ComposeDialog } from './MessagesCard'
import NotesCard from './NotesCard'
import OrderDialog from './OrderDialog'
import PendingPrints from './PendingPrints'
import PrintProblemsCard from '../orders/PrintProblemsCard'
import { usePrintProblems } from '../orders/usePrintProblems'
import ShiftDialog from './ShiftDialog'
import ShiftsCard from './ShiftsCard'
import TablesCard from './TablesCard'
@@ -73,7 +74,7 @@ export default function OverviewPage() {
const dayOpen = !!day
const cards = tableCards(tables, orders)
const waiting = cards.filter(c => c.pendingPrint)
const waiting = usePrintProblems().data?.problems ?? [] // 6.10: tickets that didn't print
const today = dayOrders(orders, day?.opened_at)
const k = dayKpis({ cards, orders: today, shifts })
const idle = staff.filter(w => w.role === 'waiter' && !shifts.some(s => s.waiter_id === w.id))
@@ -160,6 +161,8 @@ export default function OverviewPage() {
<div className="grid gap-5 lg:grid-cols-[13fr_7fr] items-start">
<div className="grid gap-5 min-w-0">
{/* 6.10: tickets that didn't print come first: they need someone now */}
<PrintProblemsCard onOpen={(id, table) => setOrder({ id, table: table ?? `#${id}` })} />
<ShiftsCard shifts={shifts} idle={idle} dayOpen={dayOpen} hidden={hidden} canMessage={chatOn}
onStart={startShift}
onEnd={s => setShift({ shift: s, mode: 'close' })}
@@ -169,7 +172,6 @@ export default function OverviewPage() {
<Card title={t('overview.revenueByHour')} testId="revenue-chart">
<div className="p-4"><HourBars buckets={hourBuckets(orderPairs(today), hourOf)} current={nowHour} /></div>
</Card>
<PendingPrints cards={waiting} onOpen={(id, table) => setOrder({ id, table })} />
</div>
<div className="grid gap-5 min-w-0">
{notesOn && <NotesCard />}
@@ -1,74 +0,0 @@
// Orders with lines that haven't printed (plan step 6.2): which table, since when, how many
// retries, the lines waiting; print one again or all of them, or open the order.
import { useState } from 'react'
import { useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { Printer } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button } from '@xenia/ui'
import client from '../../api/client'
import { printRetries, tableName } from './overviewLogic'
import { Card, Pill } from './parts'
export default function PendingPrints({ cards, onOpen }) {
const { t } = useTranslation('manager')
const { formatTime } = useFormat()
const qc = useQueryClient()
const [busy, setBusy] = useState(null) // an order id, or 'all'
if (cards.length === 0) return null
async function retry(orderId) {
try {
const res = await client.post(`/api/orders/${orderId}/retry-print`)
const failed = (res.data.print_results ?? []).filter(r => !r.success).map(r => r.printer_name)
if (failed.length) toast.error(t('overview.prints.failed', { printers: failed.join(', ') }))
else toast.success(t('overview.prints.done'))
} catch (err) {
toast.error(errorMessage(err, t))
}
}
async function run(id, fn) {
setBusy(id)
try { await fn() } finally {
setBusy(null)
qc.invalidateQueries({ queryKey: ['orders-active'] })
}
}
return (
<Card tone="warning" testId="pending-prints"
title={<span className="grid">
<span>{t('overview.prints.title')}</span>
<span className="text-label font-normal">{t('overview.prints.count', { count: cards.length })}</span>
</span>}
action={<Button size="sm" variant="secondary" icon={<Printer size={16} />} loading={busy === 'all'} disabled={busy != null}
onClick={() => run('all', async () => { for (const c of cards) await retry(c.order.id) })}>{t('overview.prints.all')}</Button>}>
<ul className="divide-y divide-line">
{cards.map(({ table, order }) => {
const waiting = order.items.filter(i => i.status === 'active' && !i.printed)
const retries = printRetries(order)
return (
<li key={order.id} className="flex items-center gap-3 px-4 py-2.5" data-testid="pending-print">
<span className="w-10 h-10 shrink-0 grid place-items-center rounded-control bg-warning-soft text-warning-ink text-label font-bold">{tableName(table)}</span>
<div className="flex-1 min-w-0">
<div className="flex flex-wrap items-center gap-2 text-label">
<span className="font-semibold text-ink">#{order.id}</span>
{order.opened_at && <span className="text-ink-2">{formatTime(order.opened_at)}</span>}
{retries > 0 && <Pill tone="warning">{t('overview.prints.retries', { count: retries })}</Pill>}
</div>
<div className="text-caption text-ink-2 truncate">
{t('overview.prints.lines', { count: waiting.length })} · {waiting.map(i => i.product?.name || `#${i.product_id}`).join(', ')}
</div>
</div>
<Button size="sm" variant="ghost" onClick={() => onOpen(order.id, tableName(table))}>{t('overview.prints.open')}</Button>
<Button size="sm" variant="secondary" loading={busy === order.id} disabled={busy != null}
onClick={() => run(order.id, () => retry(order.id))}>{t('overview.prints.print')}</Button>
</li>
)
})}
</ul>
</Card>
)
}
@@ -203,12 +203,6 @@ export function notesPreview(notes = [], todos = []) {
].slice(0, 6)
}
/** The highest retry count among an order's waiting print jobs. */
export function printRetries(order) {
const waiting = (order.print_jobs ?? []).filter(j => j.status === 'pending').map(j => j.retry_count || 0)
return waiting.length ? Math.max(...waiting) : 0
}
/**
* The venue's wall clock for a moment, as a datetime-local value ("YYYY-MM-DDTHH:mm").
* Bookings are typed in venue time; the backend reads a time without an offset as venue time (D-11).