feat(backend,waiter,manager): moves between tables and orders on the record

Owner 2026-11-23 (plan 6F.4). services/moves.py: every table transfer, lines moved and orders merged
is an order_moves row with its lines (order_move_items: line, quantity then); OrderItem.split_from_id
links a split part to its line, so a part carries the moves made before the split; combining moves
the removed lines' moves to the kept one. Alembic 0048: the tables, the column, and a backfill from
the audit notes written before (note='backfill'). A split part now also keeps the line's price change,
kitchen state, course, cost and names (it used to restart as pending at the menu price).
GET /api/orders/{id}/moves (the order's path, each line's); GET /api/reports/moves (+ export).
Waiter: a moved order's banner (T2 -> T5), moved lines marked, a line's Move history. Manager: the
order's Moves tab, each moved line's path, Reports -> Moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 08:03:11 +02:00
co-authored by Claude Opus 5.5
parent f87f9ff23c
commit 0a353c5f97
27 changed files with 903 additions and 18 deletions
+55
View File
@@ -0,0 +1,55 @@
// Where an order or a line came from (plan 6F.4): GET /api/orders/{id}/moves gives the whole
// order's path (table transfers, orders joined into it) and each moved line's (its own moves, and
// its parent's before it was split from it), however many times it moved.
import { useFormat, useTranslation } from '@xenia/i18n'
import { pathText } from '../logic/moves'
/** The banner over a moved order: its path, tap for the details. */
export function MovedOrderBanner({ moves, onOpen }) {
const { t } = useTranslation('waiter')
if (!moves?.length) return null
return (
<button type="button" onClick={onOpen} data-testid="order-moved" style={{
width: '100%', display: 'flex', alignItems: 'center', gap: 8, margin: '0 0 8px', padding: '8px 12px', borderRadius: 10,
border: '1px solid rgb(var(--x-info-rgb) / 0.35)', background: 'rgb(var(--x-info-rgb) / 0.1)', color: 'var(--x-info)',
fontSize: 13, fontWeight: 700, cursor: 'pointer', textAlign: 'left',
}}>
<span aria-hidden="true">↪</span>
<span style={{ flex: 1 }}>{t('moves.orderCame', { path: pathText(moves) })}</span>
<span style={{ fontSize: 12, fontWeight: 600 }}>{t('moves.details')}</span>
</button>
)
}
export default function MoveHistory({ title, subtitle, moves, itemId, onClose }) {
const { t } = useTranslation('waiter')
const { formatDateTime, formatNumber } = useFormat()
return (
<div className="modal-overlay" onClick={onClose}>
<div className="modal-sheet" onClick={e => e.stopPropagation()} data-testid="move-history">
<div className="modal-handle" />
<h2 className="modal-title">{title}</h2>
{subtitle && <p style={{ textAlign: 'center', color: 'var(--muted)', fontSize: 13, margin: '0 0 14px' }}>{subtitle}</p>}
<div style={{ display: 'grid', gap: 8 }}>
{moves.map(m => {
const mine = itemId != null ? m.items.find(i => i.item_id === itemId) : null
return (
<div key={m.id} data-testid="move-row" style={{ padding: '10px 12px', borderRadius: 12, background: 'var(--bg3)', border: '1px solid var(--border)', display: 'grid', gap: 2 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 8, fontWeight: 700 }}>
<span>{m.from_table || '—'} → {m.to_table || '—'}</span>
<span style={{ fontSize: 12, color: 'var(--muted)', fontWeight: 600 }}>{t(`moves.kind.${m.kind}`)}</span>
</div>
<div style={{ fontSize: 12, color: 'var(--muted)' }}>
{formatDateTime(m.at, 'datetimeShort')}{m.by ? ` · ${m.by}` : ''}
{mine?.quantity != null ? ` · ×${formatNumber(mine.quantity, { maxDecimals: 3 })}` : ''}
{itemId == null ? ` · ${t('moves.lines', { count: m.items.length })}` : ''}
</div>
</div>
)
})}
</div>
<button className="btn btn--secondary" style={{ width: '100%', marginTop: 16 }} onClick={onClose}>{t('common.close')}</button>
</div>
</div>
)
}
+10 -2
View File
@@ -320,7 +320,7 @@ function MergedBadge({ item }) {
// ── ItemRow ───────────────────────────────────────────────────────────────────
function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast, kdsDisplayStyle, orderItemLayout, waiterMap, courses, priceEvents }) {
function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast, kdsDisplayStyle, orderItemLayout, waiterMap, courses, priceEvents, moved = false }) {
const { t } = useTranslation('waiter')
const isPaid = item.status === 'paid'
const isCancelled = item.status === 'cancelled'
@@ -404,6 +404,13 @@ function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast, kd
{item.product?.name || `#${item.product_id}`}
{courseBadge}
{sourceBadge}
{moved && (
<span data-testid="item-moved" title={t('moves.lineMoved')}
style={{ marginLeft: 6, fontSize: 10, fontWeight: 800, padding: '1px 5px', borderRadius: 4, verticalAlign: 'middle',
background: 'rgb(var(--x-info-rgb) / 0.15)', color: 'var(--x-info)', border: '1px solid rgb(var(--x-info-rgb) / 0.35)' }}>
↪ {t('moves.movedShort')}
</span>
)}
</span>
)
@@ -681,7 +688,7 @@ function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast, kd
)
}
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem, waiterMap, courses = [], priceEventsMap = {} }) {
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem, waiterMap, courses = [], priceEventsMap = {}, movedItems = {} }) {
const { t } = useTranslation('waiter')
const kdsDisplayStyle = useTableViewStore(s => s.kdsDisplayStyle || 'badge')
const orderItemLayout = useTableViewStore(s => s.orderItemLayout || 'compact')
@@ -710,6 +717,7 @@ export default function OrderSummary({ order, selectable = false, selectedIds =
waiterMap={waiterMap}
courses={courses}
priceEvents={priceEventsMap[item.id] ?? []}
moved={!!movedItems[item.id]}
/>
))}
<div className="order-summary__total">
+9
View File
@@ -0,0 +1,9 @@
// Moves (plan 6F.4), plain JS so Node tests can import it.
/** "T2 → T5 → T7": the tables in the order they were visited ('—' for no table). */
export function pathText(moves) {
if (!moves?.length) return ''
const stops = [moves[0].from_table || '—']
for (const m of moves) stops.push(m.to_table || '—')
return stops.join(' → ')
}
+36 -1
View File
@@ -19,6 +19,7 @@ import { parseNumber, useTranslation } from '@xenia/i18n'
import PriceReason from '../components/PriceReason'
import { priceReasonText } from '../logic/priceRules'
import PriceHistory from '../components/PriceHistory'
import MoveHistory, { MovedOrderBanner } from '../components/MoveHistory'
import { usePriceRules } from '../hooks/usePriceRules'
import { fade } from '../logic/colour'
import SeatsHint from '../components/SeatsHint'
@@ -265,7 +266,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, onClose }) {
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, onCombine, canCancel, cancelNeedsApproval, priceAdjAllowed, priceNeedsApproval, canMove, onAdjustPrice, canSeePriceHistory, onPriceHistory, movedLine, onMoveHistory, onClose }) {
const { t } = useTranslation('waiter')
const { items, singleStacked, multiSelect } = target
const label = multiSelect
@@ -273,6 +274,21 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
: items[0]?.product?.name || `#${items[0]?.product_id}`
const actionRows = [
// 6F.4: where this line has been (tables, orders), however many moves
...(!multiSelect && movedLine ? [{
key: 'move_history',
color: 'var(--x-info)',
iconBg: 'rgb(var(--x-info-rgb) / 0.15)',
label: t('moves.lineTitle'),
sub: t('moves.lineSub'),
icon: (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
<path d="M4 7h11l-3-3M20 17H9l3 3" stroke="var(--x-info)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
),
onClick: onMoveHistory,
enabled: true,
}] : []),
// 6F.3: who changed this line's price, when, from what, why (ordering.prices.view_changes)
...(!multiSelect && canSeePriceHistory && items[0]?.price_adjustment ? [{
key: 'price_history',
@@ -1166,6 +1182,8 @@ export default function TableDetailPage() {
const [customerCountOpen, setCustomerCountOpen] = useState(false)
const [showDiscountModal, setShowDiscountModal] = useState(false)
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 }
const [cancelConfirm, setCancelConfirm] = useState(null) // null | { mode: 'items', ids: [...] } | { mode: 'order' }
const [paidSelectedIds, setPaidSelectedIds] = useState([])
@@ -1331,6 +1349,14 @@ export default function TableDetailPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [order?.id, order?.items?.length])
// 6F.4: the order's path and its moved lines (a transfer changes the table, a move the items)
useEffect(() => {
if (!order?.id) { setMoves({ order: [], items: {} }); return }
client.get(`/api/orders/${order.id}/moves`)
.then(r => setMoves({ order: r.data?.order ?? [], items: r.data?.items ?? {} }))
.catch(() => {})
}, [order?.id, order?.items?.length, order?.table_id])
// Handle ?action= param from table list long-press quick actions
useEffect(() => {
const action = searchParams.get('action')
@@ -1903,6 +1929,7 @@ export default function TableDetailPage() {
{activeTab === 'active' && (
<>
<MovedOrderBanner moves={moves.order} onOpen={() => setMoveSheet({ title: t('moves.orderTitle'), moves: moves.order })} />
<OrderSummary
order={{ ...order, items: displayActiveItems }}
selectable={canInteract && !paying}
@@ -1910,6 +1937,7 @@ export default function TableDetailPage() {
onToggle={toggleItem}
waiterMap={waiterMap}
priceEventsMap={priceEventsMap}
movedItems={moves.items}
onLongPressItem={(item) => {
if (selectedIds.length > 1) {
const items = displayActiveItems.filter(i => selectedIds.includes(i.id))
@@ -2236,6 +2264,12 @@ export default function TableDetailPage() {
setPriceAdjustItem(item)
}}
canSeePriceHistory={seesPriceChanges && !isOffline}
movedLine={!!moves.items[itemActionTarget.items[0]?.id]}
onMoveHistory={() => {
const item = itemActionTarget.items[0]
setItemActionTarget(null)
setMoveSheet({ title: t('moves.lineTitle'), subtitle: item.product_name || item.product?.name, moves: moves.items[item.id] ?? [], itemId: item.id })
}}
onPriceHistory={() => {
const item = itemActionTarget.items[0]
setItemActionTarget(null)
@@ -2285,6 +2319,7 @@ export default function TableDetailPage() {
)}
{historyItem && <PriceHistory orderId={order.id} item={historyItem} onClose={() => setHistoryItem(null)} />}
{moveSheet && <MoveHistory {...moveSheet} onClose={() => setMoveSheet(null)} />}
{/* Cancel confirmation */}
{cancelConfirm && (
+7
View File
@@ -25,3 +25,10 @@ test('the reason sent: a quick reason, a typed one, or none', async () => {
const own = priceRules(set({ 'orders.price_change_reasons': '["Friend"]' }))
assert.equal(priceReasonText(own, t, { choice: 'v0' }), 'Friend')
})
test('a moved order\'s path (6F.4)', async () => {
const { pathText } = await import('../src/logic/moves.js')
assert.equal(pathText([]), '')
assert.equal(pathText([{ from_table: 'T2', to_table: 'T5' }, { from_table: 'T5', to_table: 'T7' }]), 'T2 → T5 → T7')
assert.equal(pathText([{ from_table: null, to_table: 'T1' }]), '— → T1')
})