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">