feat: ordering from the menu tablet at a table (platform-v2 step 6.6, D-30)

- tablet_orders (0034) + services/tablet_orders.py: venue rules (menu_tablet.ordering) with
  per-tablet overrides: kitchen or waiter confirms first, no open order open/refuse, limits
  (items per order, of one dish, time between orders)
- /api/menu-tablet: quote, order, order/{id}, bill (see + ask), requests accept/decline, ordering
- terminal: Add to the order (POS ProductDialog), cart, note, send, live status, the bill
- waiter: TabletRequests on the table page, tablet_order message theme with Open the table
- manager: Settings -> Menu tablets
- tests: test_tablet_orders.py, menu-tablet unit, menu_tablet.mjs e2e (the done-when)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 14:42:37 +02:00
co-authored by Claude Opus 5.5
parent c43dc8b55b
commit c1af7770cf
34 changed files with 1491 additions and 28 deletions
@@ -0,0 +1,87 @@
// Orders from the table's menu tablet that wait for a waiter (plan step 6.6, D-30): when the
// venue (or the tablet) says a waiter confirms tablet orders first, they show here on the table,
// with what the guests chose and their note. Accept sends it to the table's order and the
// kitchen; Decline tells the tablet, with a reason the guests see. Refreshes on the live event
// `tablet_order_updated` and after a reconnect. Shows nothing when none wait.
import { useCallback, useEffect, useState } from 'react'
import { useCan, useModule } from '@xenia/access'
import { useTranslation } from '@xenia/i18n'
import client from '../api/client'
import { apiError } from '../api/errors'
import { money } from '../i18n'
export default function TabletRequests({ tableId }) {
const { t } = useTranslation('waiter')
const moduleOn = useModule('menu_tablet')
const canOpen = useCan('ordering.orders.open')
const on = moduleOn && canOpen
const [list, setList] = useState([])
const [declining, setDeclining] = useState(null)
const [reason, setReason] = useState('')
const [busy, setBusy] = useState(null)
const [problem, setProblem] = useState(null)
const load = useCallback(async () => {
if (!on) return
try { setList((await client.get('/api/menu-tablet/requests', { params: { table_id: tableId } })).data) } catch { /* offline: keep */ }
}, [on, tableId])
useEffect(() => {
const first = setTimeout(load, 0)
const onEvent = e => { if (['tablet_order_updated', 'ready'].includes(e.detail?.type) && (!e.detail?.data?.table_id || e.detail.data.table_id === tableId)) load() }
window.addEventListener('live-event', onEvent)
window.addEventListener('live-reconnected', load)
return () => { clearTimeout(first); window.removeEventListener('live-event', onEvent); window.removeEventListener('live-reconnected', load) }
}, [load, tableId])
const answer = async (id, action, body) => {
setBusy(id)
setProblem(null)
try {
await client.post(`/api/menu-tablet/requests/${id}/${action}`, body ?? {})
setDeclining(null)
await load()
} catch (err) { setProblem(apiError(err, t('tabletOrder.title'))) } finally { setBusy(null) }
}
if (!on || list.length === 0) return null
return (
<div style={{ margin: '10px 12px 0', display: 'grid', gap: 8 }} data-testid="tablet-requests">
{list.map(r => (
<div key={r.id} data-testid="tablet-request" data-id={r.id}
style={{ border: '2px solid var(--x-warning)', background: 'var(--x-warning-soft)', borderRadius: 14, padding: 12, display: 'grid', gap: 8 }}>
<div style={{ fontWeight: 800, color: 'var(--x-warning-ink)' }}>📱 {t('tabletOrder.title')}</div>
<div style={{ fontSize: 13, color: 'var(--x-ink-2)' }}>{t('tabletOrder.body')}</div>
<div style={{ display: 'grid', gap: 4 }}>
{r.lines.map((l, i) => (
<div key={i} style={{ display: 'flex', justifyContent: 'space-between', gap: 8, color: 'var(--x-ink)' }}>
<span><b>{l.quantity}×</b> {l.name}{l.entries?.length ? <span style={{ color: 'var(--x-ink-2)' }}> · {l.entries.join(', ')}</span> : null}</span>
<span style={{ fontVariantNumeric: 'tabular-nums' }}>{money(l.total)}</span>
</div>
))}
</div>
{r.note && <div style={{ fontSize: 13, color: 'var(--x-ink)' }}>{t('tabletOrder.note', { note: r.note })}</div>}
{declining === r.id ? (
<div style={{ display: 'grid', gap: 6 }}>
<label style={{ fontSize: 12, color: 'var(--x-ink-2)' }}>{t('tabletOrder.reason')}
<input className="input" value={reason} onChange={e => setReason(e.target.value)} style={{ width: '100%', marginTop: 4 }} />
</label>
<div style={{ display: 'flex', gap: 8 }}>
<button className="btn btn--secondary" style={{ flex: 1 }} onClick={() => setDeclining(null)}>{t('common.back', { defaultValue: '←' })}</button>
<button className="btn btn--danger" style={{ flex: 1 }} disabled={busy === r.id} data-testid="tablet-request-decline-confirm"
onClick={() => answer(r.id, 'decline', { reason: reason.trim() || null })}>{t('tabletOrder.decline')}</button>
</div>
</div>
) : (
<div style={{ display: 'flex', gap: 8 }}>
<button className="btn btn--secondary" style={{ flex: 1 }} disabled={busy === r.id} data-testid="tablet-request-decline"
onClick={() => { setReason(t('tabletOrder.reasonDefault')); setDeclining(r.id) }}>{t('tabletOrder.decline')}</button>
<button className="btn btn--primary" style={{ flex: 2 }} disabled={busy === r.id} data-testid="tablet-request-accept"
onClick={() => answer(r.id, 'accept')}>{t('tabletOrder.accept')} · {money(r.total)}</button>
</div>
)}
</div>
))}
{problem && <div role="alert" style={{ color: 'var(--x-danger-ink)', fontSize: 13 }}>{problem}</div>}
</div>
)
}