feat(backend,waiter,terminal,manager): +1 on a sent line and changing a line's quantity

Owner 2026-11-23 (plan 6F.5). Product flag one_more_enabled (off by default; product editor).
POST /api/orders/{id}/items/{item}/again: a new line like the old one (choices, removed, note,
course), priced now, sent to the kitchen like any new line. Waiter app and the counter's table
panel: +1 beside such lines; the first tap arms it, more taps count up, 'Send +N' sends, 4 s idle
disarms (no stray sends).
POST /api/orders/{id}/items/{item}/quantity: venue setting orders.quantity_change (off | add_only |
add_and_remove, default off), key ordering.items.change_quantity (owner, store manager; Alembic 0049
grants it); up only changes the line, down cuts a cancelled part ('quantity lowered', split_from_id)
and prints a cancellation only when asked (the dialog presets yes while the kitchen hasn't finished).
Waiter: 'Change quantity' in a line's actions (now -> new, -/+). cut_part() now shared with split.
GET /api/orders/{id} items carry the product's one_more_enabled / unit_type, deal ids, split_from_id,
cancel_reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 08:26:46 +02:00
co-authored by Claude Opus 5.5
parent 0a353c5f97
commit 72e175ab73
35 changed files with 813 additions and 35 deletions
+45
View File
@@ -0,0 +1,45 @@
// "+1" on a sent line (plan 6F.5): one more of the same, sent to the kitchen like any new line.
// Nothing goes out on one stray tap: the first tap arms it (+1), more taps count up (+2, +3…),
// "Send" sends; 4 s without a tap puts it back.
import { useEffect, useRef, useState } from 'react'
import { useTranslation } from '@xenia/i18n'
const WAIT_MS = 4000
export default function OneMore({ onSend }) {
const { t } = useTranslation('waiter')
const [count, setCount] = useState(0)
const [busy, setBusy] = useState(false)
const timer = useRef(null)
useEffect(() => () => clearTimeout(timer.current), [])
const rearm = () => { clearTimeout(timer.current); timer.current = setTimeout(() => setCount(0), WAIT_MS) }
const stop = e => { e.stopPropagation() }
const tap = e => { stop(e); if (busy) return; setCount(c => Math.min(c + 1, 20)); rearm() }
const send = async e => {
stop(e)
if (busy || !count) return
clearTimeout(timer.current)
setBusy(true)
try { await onSend(count) } finally { setBusy(false); setCount(0) }
}
const round = {
width: 40, height: 40, borderRadius: '50%', flexShrink: 0, cursor: 'pointer', fontWeight: 800, fontSize: 14,
border: '1.5px solid rgb(var(--x-success-rgb) / 0.55)', background: count ? 'var(--x-success)' : 'rgb(var(--x-success-rgb) / 0.1)',
color: count ? 'rgb(var(--x-success-fg-rgb))' : 'var(--x-success)',
}
return (
<div onClick={stop} onTouchStart={stop} style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '0 8px 0 4px' }} data-testid="one-more" data-armed={count ? 'true' : 'false'}>
{count > 0 && (
<button type="button" onClick={send} disabled={busy} data-testid="one-more-send" style={{
height: 36, padding: '0 12px', borderRadius: 18, border: 'none', cursor: 'pointer', fontWeight: 800, fontSize: 13,
background: 'var(--x-success)', color: 'rgb(var(--x-success-fg-rgb))', whiteSpace: 'nowrap',
}}>
{busy ? '…' : t('oneMore.send', { count })}
</button>
)}
<button type="button" onClick={tap} aria-label={t('oneMore.label')} style={round} data-testid="one-more-tap">
+{count || 1}
</button>
</div>
)
}
+9 -2
View File
@@ -3,6 +3,8 @@ import useTableViewStore from '../store/tableViewStore'
import { money } from '../i18n'
import { useTranslation } from '@xenia/i18n'
import { fade } from '../logic/colour'
import OneMore from './OneMore'
import { canOneMore } from '../logic/lines'
const fmtPrice = money
@@ -688,7 +690,7 @@ function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast, kd
)
}
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem, waiterMap, courses = [], priceEventsMap = {}, movedItems = {} }) {
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem, waiterMap, courses = [], priceEventsMap = {}, movedItems = {}, onOneMore }) {
const { t } = useTranslation('waiter')
const kdsDisplayStyle = useTableViewStore(s => s.kdsDisplayStyle || 'badge')
const orderItemLayout = useTableViewStore(s => s.orderItemLayout || 'compact')
@@ -704,8 +706,10 @@ export default function OrderSummary({ order, selectable = false, selectedIds =
<div className="order-summary">
{activeItems.length === 0 && <p style={{ color: 'var(--x-ink-3)', textAlign: 'center' }}>{t('summary.noItems')}</p>}
{activeItems.map((item, idx) => (
// 6F.5: "+1" beside a line whose product allows it, outside the line's own tap area
<div key={item.id} style={{ display: 'flex', alignItems: 'center' }}>
<div style={{ flex: 1, minWidth: 0 }}>
<ItemRow
key={item.id}
item={item}
selectable={selectable}
selected={selectedIds.includes(item.id)}
@@ -719,6 +723,9 @@ export default function OrderSummary({ order, selectable = false, selectedIds =
priceEvents={priceEventsMap[item.id] ?? []}
moved={!!movedItems[item.id]}
/>
</div>
{onOneMore && canOneMore(item) && <OneMore onSend={qty => onOneMore(item, qty)} />}
</div>
))}
<div className="order-summary__total">
<span>{t('common.total')}</span>
@@ -0,0 +1,57 @@
// Change a sent line's quantity (plan 6F.5): nothing is sent to the kitchen again. The current
// quantity stays big beside the new one so a slip is seen; lowering it cancels the difference and
// asks whether to send a cancellation (yes while the kitchen hasn't finished it).
import { useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import { cancelByDefault, lowestQuantity } from '../logic/lines'
export default function QuantityModal({ item, mode, error, busy, onSave, onClose }) {
const { t } = useTranslation('waiter')
const now = item.quantity
const [qty, setQty] = useState(now)
const [ticket, setTicket] = useState(() => cancelByDefault(item))
const low = lowestQuantity(item, mode)
const lowering = qty < now
const step = d => setQty(q => Math.max(low, Math.min(999, q + d)))
const btn = { width: 56, height: 56, borderRadius: '50%', border: '1.5px solid var(--border)', background: 'var(--bg3)', fontSize: 26, fontWeight: 700, color: 'var(--text)', cursor: 'pointer' }
return (
<div className="modal-overlay" onClick={busy ? undefined : onClose}>
<div className="modal-sheet" onClick={e => e.stopPropagation()} data-testid="quantity-sheet">
<div className="modal-handle" />
<h2 className="modal-title">{t('quantity.title')}</h2>
<p style={{ textAlign: 'center', color: 'var(--muted)', fontSize: 13, margin: '0 0 14px' }}>{item.product_name || item.product?.name}</p>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 18, marginBottom: 6 }}>
<div style={{ textAlign: 'center' }}>
<div style={{ fontSize: 12, color: 'var(--muted)', fontWeight: 700 }}>{t('quantity.now')}</div>
<div style={{ fontSize: 30, fontWeight: 800, color: 'var(--muted)' }} data-testid="quantity-now">{now}</div>
</div>
<span style={{ fontSize: 22, color: 'var(--muted)' }}>→</span>
<div style={{ textAlign: 'center' }}>
<div style={{ fontSize: 12, color: 'var(--muted)', fontWeight: 700 }}>{t('quantity.new')}</div>
<div style={{ fontSize: 44, fontWeight: 800, color: qty === now ? 'var(--text)' : lowering ? 'var(--x-danger)' : 'var(--x-success)' }} data-testid="quantity-new">{qty}</div>
</div>
</div>
<div style={{ display: 'flex', justifyContent: 'center', gap: 28, margin: '8px 0 14px' }}>
<button type="button" style={btn} onClick={() => step(-1)} disabled={qty <= low} aria-label={t('quantity.less')} data-testid="quantity-less">−</button>
<button type="button" style={btn} onClick={() => step(1)} aria-label={t('quantity.more')} data-testid="quantity-more">+</button>
</div>
<p style={{ textAlign: 'center', fontSize: 13, color: 'var(--muted)', margin: '0 0 12px' }}>
{qty > now ? t('quantity.upNote', { count: qty - now }) : lowering ? t('quantity.downNote', { count: now - qty }) : t('quantity.noChange')}
</p>
{mode === 'add_only' && <p style={{ textAlign: 'center', fontSize: 12, color: 'var(--muted)', margin: '0 0 12px' }}>{t('quantity.onlyUp')}</p>}
{lowering && (
<label style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '10px 12px', borderRadius: 12, background: 'var(--bg3)', border: '1px solid var(--border)', marginBottom: 12, fontSize: 14 }}>
<input type="checkbox" checked={ticket} onChange={e => setTicket(e.target.checked)} data-testid="quantity-ticket" style={{ width: 20, height: 20 }} />
<span>{t('quantity.sendCancel')}</span>
</label>
)}
{error && <p role="alert" style={{ color: 'var(--x-danger)', fontSize: 13, textAlign: 'center', margin: '0 0 10px' }}>{error}</p>}
<div style={{ display: 'flex', gap: 10 }}>
<button className="btn btn--secondary" style={{ flex: 1 }} onClick={onClose} disabled={busy}>{t('common.cancel')}</button>
<button className={lowering ? 'btn btn--danger' : 'btn btn--primary'} style={{ flex: 1 }} disabled={busy || qty === now}
onClick={() => onSave(qty, lowering && ticket)} data-testid="quantity-save">{t('quantity.save')}</button>
</div>
</div>
</div>
)
}
+14
View File
@@ -0,0 +1,14 @@
// The venue's orders.quantity_change (6F.5, logic/lines.js), from the shared settings request.
import { useEffect, useState } from 'react'
import { getVenueSettings } from '../api/venueSettings'
import { quantityMode } from '../logic/lines'
export function useQuantityMode() {
const [mode, setMode] = useState('off')
useEffect(() => {
let alive = true
getVenueSettings().then(r => { if (alive) setMode(quantityMode(r.data)) }).catch(() => {})
return () => { alive = false }
}, [])
return mode
}
+31
View File
@@ -0,0 +1,31 @@
// A sent line's "one more" and quantity rules (plan 6F.5). Plain JS so Node tests can import it.
/** The venue's orders.quantity_change: 'off' | 'add_only' | 'add_and_remove'. */
export function quantityMode(settings) {
const v = settings?.['orders.quantity_change']?.value
return ['off', 'add_only', 'add_and_remove'].includes(v) ? v : 'off'
}
const PIECE = item => (item?.unit_type || item?.product?.unit_type || 'piece') === 'piece'
/** A line that shows +1: its product allows it, counted in pieces, not cancelled, not a deal's. */
export function canOneMore(item) {
return !!item?.product?.one_more_enabled && PIECE(item) && ['active', 'paid', 'tabbed'].includes(item.status)
&& !item.deal_id && !item.linked_item_id
}
/** A line whose quantity may change: unpaid, in whole pieces, not a deal's. */
export function canChangeQuantity(item, mode) {
return mode !== 'off' && item?.status === 'active' && PIECE(item) && Number.isInteger(item.quantity)
&& !item.deal_id && !item.linked_item_id
}
/** Lowering a line: send a cancellation to the kitchen? Yes while it is still waiting or being made. */
export function cancelByDefault(item) {
return ['pending', 'preparing'].includes(item?.kds_status || 'pending')
}
/** The lowest quantity the dialog allows. */
export function lowestQuantity(item, mode) {
return mode === 'add_and_remove' ? 1 : item.quantity
}
+57 -1
View File
@@ -20,6 +20,9 @@ import PriceReason from '../components/PriceReason'
import { priceReasonText } from '../logic/priceRules'
import PriceHistory from '../components/PriceHistory'
import MoveHistory, { MovedOrderBanner } from '../components/MoveHistory'
import QuantityModal from '../components/QuantityModal'
import { useQuantityMode } from '../hooks/useQuantityMode'
import { canChangeQuantity } from '../logic/lines'
import { usePriceRules } from '../hooks/usePriceRules'
import { fade } from '../logic/colour'
import SeatsHint from '../components/SeatsHint'
@@ -266,7 +269,7 @@ function PriceAdjustModal({ item, rules, error, onConfirm, onClose }) {
// ─── Item action modal (long-press) ──────────────────────────────────────────
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, onCombine, canCancel, cancelNeedsApproval, priceAdjAllowed, priceNeedsApproval, canMove, onAdjustPrice, canSeePriceHistory, onPriceHistory, movedLine, onMoveHistory, onClose }) {
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, onCombine, canCancel, cancelNeedsApproval, priceAdjAllowed, priceNeedsApproval, canMove, onAdjustPrice, canSeePriceHistory, onPriceHistory, movedLine, onMoveHistory, canChangeQty, onChangeQty, onClose }) {
const { t } = useTranslation('waiter')
const { items, singleStacked, multiSelect } = target
const label = multiSelect
@@ -274,6 +277,22 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
: items[0]?.product?.name || `#${items[0]?.product_id}`
const actionRows = [
// 6F.5: correct how many there are, without sending it to the kitchen again
...(!multiSelect && canChangeQty ? [{
key: 'change_quantity',
color: 'var(--x-accent)',
iconBg: 'rgb(var(--x-accent-rgb) / 0.15)',
label: t('quantity.title'),
sub: t('quantity.actionSub'),
icon: (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
<path d="M5 12h4M7 10v4M15 12h4" stroke="var(--x-accent)" strokeWidth="2" strokeLinecap="round" />
<rect x="2" y="5" width="20" height="14" rx="3" stroke="var(--x-accent)" strokeWidth="2" />
</svg>
),
onClick: onChangeQty,
enabled: true,
}] : []),
// 6F.4: where this line has been (tables, orders), however many moves
...(!multiSelect && movedLine ? [{
key: 'move_history',
@@ -1184,6 +1203,12 @@ export default function TableDetailPage() {
const [priceEventsMap, setPriceEventsMap] = useState({})
const [moves, setMoves] = useState({ order: [], items: {} }) // 6F.4: where the order and its lines came from
const [moveSheet, setMoveSheet] = useState(null) // { title, subtitle, moves, itemId }
// 6F.5: a line's quantity (no new ticket) and "+1" (one more, sent as new)
const quantityMode = useQuantityMode()
const quantityAccess = useAllowed('ordering.items.change_quantity')
const [qtyItem, setQtyItem] = useState(null)
const [qtyError, setQtyError] = useState('')
const [qtyBusy, setQtyBusy] = useState(false)
const [cancelConfirm, setCancelConfirm] = useState(null) // null | { mode: 'items', ids: [...] } | { mode: 'order' }
const [paidSelectedIds, setPaidSelectedIds] = useState([])
@@ -1938,6 +1963,12 @@ export default function TableDetailPage() {
waiterMap={waiterMap}
priceEventsMap={priceEventsMap}
movedItems={moves.items}
onOneMore={canInteract && !paying && !isOffline ? async (item, qty) => {
try {
await client.post(`/api/orders/${order.id}/items/${item.id}/again`, { quantity: qty })
await load()
} catch (err) { setError(apiError(err, t('detail.err.again'))) }
} : undefined}
onLongPressItem={(item) => {
if (selectedIds.length > 1) {
const items = displayActiveItems.filter(i => selectedIds.includes(i.id))
@@ -2027,6 +2058,12 @@ export default function TableDetailPage() {
<>
<OrderSummary
order={{ ...order, items: paidItems }}
onOneMore={canInteract && !paying && !isOffline ? async (item, qty) => { // 6F.5: the beer already paid for
try {
await client.post(`/api/orders/${order.id}/items/${item.id}/again`, { quantity: qty })
await load()
} catch (err) { setError(apiError(err, t('detail.err.again'))) }
} : undefined}
selectable={canInteract}
selectedIds={paidSelectedIds}
waiterMap={waiterMap}
@@ -2265,6 +2302,13 @@ export default function TableDetailPage() {
}}
canSeePriceHistory={seesPriceChanges && !isOffline}
movedLine={!!moves.items[itemActionTarget.items[0]?.id]}
canChangeQty={quantityAccess !== 'no' && !isOffline && canChangeQuantity(itemActionTarget.items[0], quantityMode)}
onChangeQty={() => {
const item = itemActionTarget.items[0]
setItemActionTarget(null)
setQtyError('')
setQtyItem(item)
}}
onMoveHistory={() => {
const item = itemActionTarget.items[0]
setItemActionTarget(null)
@@ -2320,6 +2364,18 @@ export default function TableDetailPage() {
{historyItem && <PriceHistory orderId={order.id} item={historyItem} onClose={() => setHistoryItem(null)} />}
{moveSheet && <MoveHistory {...moveSheet} onClose={() => setMoveSheet(null)} />}
{qtyItem && (
<QuantityModal item={qtyItem} mode={quantityMode} error={qtyError} busy={qtyBusy}
onClose={() => { setQtyItem(null); setQtyError('') }}
onSave={async (quantity, ticket) => {
setQtyBusy(true); setQtyError('')
try {
await client.post(`/api/orders/${order.id}/items/${qtyItem.id}/quantity`, { quantity, print_cancellation: ticket })
setQtyItem(null)
await load()
} catch (err) { setQtyError(apiError(err, t('detail.err.quantity'))) } finally { setQtyBusy(false) }
}} />
)}
{/* Cancel confirmation */}
{cancelConfirm && (
+30
View File
@@ -0,0 +1,30 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { cancelByDefault, canChangeQuantity, canOneMore, lowestQuantity, quantityMode } from '../src/logic/lines.js'
const beer = (o = {}) => ({ status: 'active', quantity: 3, unit_type: 'piece', product: { one_more_enabled: true }, kds_status: 'pending', ...o })
test('one more: the product allows it, pieces, a line still there (6F.5)', () => {
assert.equal(canOneMore(beer()), true)
assert.equal(canOneMore(beer({ status: 'paid' })), true)
assert.equal(canOneMore(beer({ status: 'cancelled' })), false)
assert.equal(canOneMore(beer({ product: { one_more_enabled: false } })), false)
assert.equal(canOneMore(beer({ unit_type: 'kg' })), false)
assert.equal(canOneMore(beer({ deal_id: 4 })), false)
})
test('changing a quantity: the venue, unpaid whole pieces; how low; the ticket question', () => {
const s = v => ({ 'orders.quantity_change': { value: v } })
assert.equal(quantityMode(null), 'off')
assert.equal(quantityMode(s('add_only')), 'add_only')
assert.equal(quantityMode(s('nonsense')), 'off')
assert.equal(canChangeQuantity(beer(), 'off'), false)
assert.equal(canChangeQuantity(beer(), 'add_only'), true)
assert.equal(canChangeQuantity(beer({ status: 'paid' }), 'add_and_remove'), false)
assert.equal(canChangeQuantity(beer({ quantity: 1.5 }), 'add_and_remove'), false)
assert.equal(lowestQuantity(beer(), 'add_only'), 3)
assert.equal(lowestQuantity(beer(), 'add_and_remove'), 1)
assert.equal(cancelByDefault(beer({ kds_status: 'preparing' })), true)
assert.equal(cancelByDefault(beer({ kds_status: 'served' })), false)
assert.equal(cancelByDefault(beer({ kds_status: 'done' })), false)
})