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
@@ -2,6 +2,7 @@ import { useState } from 'react'
import { useCan, useModule } from '@xenia/access'
import { useTranslation } from '@xenia/i18n'
import CustomerDisplaySettings from './sections/CustomerDisplaySettings'
import MenuTabletSettings from './sections/MenuTabletSettings'
import VenueSettings from './sections/VenueSettings'
import AppInfoTab from './tabs/AppInfoTab'
import ColoursTab from './tabs/ColoursTab'
@@ -12,7 +13,7 @@ import DevelopmentTab from './tabs/DevelopmentTab'
import FiscalTab from './tabs/FiscalTab'
import { TabGroup } from '../../ui/Tabs'
const TABS = ['app-info', 'venue', 'customer-display', 'security', 'operation', 'colours', 'print-fonts', 'fiscal', 'development']
const TABS = ['app-info', 'venue', 'customer-display', 'menu-tablets', 'security', 'operation', 'colours', 'print-fonts', 'fiscal', 'development']
export default function SettingsPage() {
const { t } = useTranslation('manager')
@@ -21,7 +22,11 @@ export default function SettingsPage() {
const displayOn = useModule('customer_display')
const displayKey = useCan('customer_display.manage')
const display = displayOn && displayKey
const tabs = TABS.filter(id => id !== 'customer-display' || display).map(id => ({ id, label: t(`settings.tabs.${id}`) }))
// guests ordering from the menu tablets (6.6): where there are tablets and the user sets them up
const tabletOn = useModule('menu_tablet')
const tabletKey = useCan('menu_tablet.manage')
const tablets = tabletOn && tabletKey
const tabs = TABS.filter(id => (id !== 'customer-display' || display) && (id !== 'menu-tablets' || tablets)).map(id => ({ id, label: t(`settings.tabs.${id}`) }))
return (
<div className="flex flex-col h-full min-h-0">
@@ -30,6 +35,7 @@ export default function SettingsPage() {
{activeTab === 'app-info' && <AppInfoTab />}
{activeTab === 'venue' && <div className="max-w-3xl"><VenueSettings /></div>}
{activeTab === 'customer-display' && display && <div className="max-w-4xl"><CustomerDisplaySettings /></div>}
{activeTab === 'menu-tablets' && tablets && <div className="max-w-3xl"><MenuTabletSettings /></div>}
{activeTab === 'security' && <SecurityTab />}
{activeTab === 'operation' && <OperationTab />}
{activeTab === 'colours' && <ColoursTab />}
@@ -0,0 +1,74 @@
// Settings → Menu tablets (plan step 6.6, owner decisions D-30): the venue's rules for guests
// ordering from a menu tablet at a table. Each tablet can override any of them in Devices
// ("Ordering" group of its settings); a tablet takes orders only with "Guests can order" on.
// - who confirms: straight to the kitchen, or a waiter accepts each order on the phone first;
// - a table with no open order: the tablet opens one, or the guests wait until a waiter does;
// - limits: items in one order, of one dish, and the time between two orders from one tablet.
// Backend: GET / PUT /api/menu-tablet/ordering (routers/menu_tablet.py, services/tablet_orders.py).
import { useEffect, useId, useState } from 'react'
import toast from 'react-hot-toast'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Select, Spinner } from '@xenia/ui'
import client from '../../../api/client'
import { SettingRow, SettingsCard } from './SettingsCard'
const CHOICES = {
max_items: [5, 10, 15, 20, 30, 50, 100],
max_of_one: [1, 2, 3, 5, 10, 20],
min_seconds: [0, 30, 60, 120, 300, 600],
}
export default function MenuTabletSettings() {
const { t } = useTranslation('manager')
const [rules, setRules] = useState(null)
const [saving, setSaving] = useState(false)
const ids = { confirm: useId(), no_order: useId(), max_items: useId(), max_of_one: useId(), min_seconds: useId() }
useEffect(() => {
client.get('/api/menu-tablet/ordering').then(r => setRules(r.data)).catch(err => toast.error(errorMessage(err, t)))
}, [t])
if (!rules) return <div className="py-8 flex justify-center"><Spinner /></div>
const save = async (key, value) => {
const next = { ...rules, [key]: value }
setSaving(true)
try {
setRules((await client.put('/api/menu-tablet/ordering', next)).data)
toast.success(t('settings.saved'))
} catch (err) { toast.error(errorMessage(err, t)) }
setSaving(false)
}
const numbers = (key, label) => {
const list = CHOICES[key].includes(rules[key]) ? CHOICES[key] : [...CHOICES[key], rules[key]].sort((a, b) => a - b)
return list.map(v => ({ value: String(v), label: label(v) }))
}
const seconds = v => (v === 0 ? t('menuTabletSettings.noWait') : v < 60 ? t('menuTabletSettings.seconds', { count: v }) : t('menuTabletSettings.minutes', { count: v / 60 }))
return (
<SettingsCard title={t('menuTabletSettings.title')} description={t('menuTabletSettings.intro')} testId="settings-menu-tablets">
<SettingRow label={t('menuTabletSettings.confirm')} tip={t('menuTabletSettings.confirmTip')} htmlFor={ids.confirm}>
<Select id={ids.confirm} value={rules.confirm} disabled={saving} data-testid="setting-tablet-confirm"
onChange={e => save('confirm', e.target.value)}
options={['kitchen', 'waiter'].map(v => ({ value: v, label: t(`menuTabletSettings.confirms.${v}`) }))} />
</SettingRow>
<SettingRow label={t('menuTabletSettings.noOrder')} tip={t('menuTabletSettings.noOrderTip')} htmlFor={ids.no_order}>
<Select id={ids.no_order} value={rules.no_order} disabled={saving} data-testid="setting-tablet-no-order"
onChange={e => save('no_order', e.target.value)}
options={['open', 'refuse'].map(v => ({ value: v, label: t(`menuTabletSettings.noOrders.${v}`) }))} />
</SettingRow>
<SettingRow label={t('menuTabletSettings.maxItems')} tip={t('menuTabletSettings.maxItemsTip')} htmlFor={ids.max_items}>
<Select id={ids.max_items} value={String(rules.max_items)} disabled={saving} data-testid="setting-tablet-max-items"
onChange={e => save('max_items', Number(e.target.value))} options={numbers('max_items', String)} />
</SettingRow>
<SettingRow label={t('menuTabletSettings.maxOfOne')} tip={t('menuTabletSettings.maxOfOneTip')} htmlFor={ids.max_of_one}>
<Select id={ids.max_of_one} value={String(rules.max_of_one)} disabled={saving} data-testid="setting-tablet-max-of-one"
onChange={e => save('max_of_one', Number(e.target.value))} options={numbers('max_of_one', String)} />
</SettingRow>
<SettingRow label={t('menuTabletSettings.minTime')} tip={t('menuTabletSettings.minTimeTip')} htmlFor={ids.min_seconds}>
<Select id={ids.min_seconds} value={String(rules.min_seconds)} disabled={saving} data-testid="setting-tablet-min-seconds"
onChange={e => save('min_seconds', Number(e.target.value))} options={numbers('min_seconds', seconds)} />
</SettingRow>
</SettingsCard>
)
}