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:
@@ -58,6 +58,7 @@ import PrepZonesPage from './pages/reports/prepzones/PrepZonesReport'
|
||||
import ExpensesReportPage from './pages/reports/expenses/ExpensesReport'
|
||||
import TechnicalPage from './pages/reports/technical/TechnicalReport'
|
||||
import MiscPage from './pages/reports/misc/MiscReport'
|
||||
import MovesPage from './pages/reports/moves/MovesReport'
|
||||
|
||||
// Other
|
||||
import { AppsPage, IntegrationsPage } from './pages/platform/ModulesPage'
|
||||
@@ -172,6 +173,7 @@ export default function App() {
|
||||
<Route path="reports/expenses" element={<ExpensesReportPage />} />
|
||||
<Route path="reports/technical" element={<TechnicalPage />} />
|
||||
<Route path="reports/misc" element={<MiscPage />} />
|
||||
<Route path="reports/moves" element={<MovesPage />} />
|
||||
|
||||
{/* ── Apps & Settings ── */}
|
||||
<Route path="apps" element={<AppsPage />} />
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { EmptyState, cx } from '@xenia/ui'
|
||||
import { Pill } from '../overview/parts'
|
||||
import { nameOf } from './orderLogic'
|
||||
import { nameOf, pathText } from './orderLogic'
|
||||
|
||||
const EVENT_TONE = { PAYMENT: 'success', PAYMENT_OFFLINE: 'success', ORDER_CLOSED: 'neutral', ORDER_CANCELLED: 'danger', ITEM_CANCELLED: 'danger' }
|
||||
const ids = raw => { try { return raw ? JSON.parse(raw) : [] } catch { return [] } }
|
||||
@@ -76,3 +76,44 @@ export function PriceEventList({ events }) {
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
/** The order's moves (6F.4): the whole order's path (table transfers, tables joined into it), then
|
||||
* each moved line's own path, however many moves. */
|
||||
export function MoveList({ moves, order }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatDateTime, formatNumber } = useFormat()
|
||||
const byId = new Map(order.items.map(i => [i.id, i]))
|
||||
const lines = Object.entries(moves.items ?? {}).map(([id, ms]) => [byId.get(Number(id)), ms]).filter(([i]) => i)
|
||||
if (!moves.order?.length && !lines.length) return <EmptyState compact title={t('orders.moves.none')} />
|
||||
const row = (m, itemId) => {
|
||||
const mine = itemId != null ? m.items.find(i => i.item_id === itemId) : null
|
||||
return (
|
||||
<li key={`${itemId ?? 'o'}-${m.id}`} className="px-4 py-2 flex items-start gap-3" data-testid="order-move">
|
||||
<Pill tone="info">{t(`orders.moves.kind.${m.kind}`)}</Pill>
|
||||
<span className="flex-1 min-w-0 text-label text-ink">
|
||||
<span className="font-semibold">{m.from_table || '—'} → {m.to_table || '—'}</span>
|
||||
{m.by && <span className="ml-2 text-ink-3">{t('orders.history.by', { name: m.by })}</span>}
|
||||
{mine?.quantity != null && <span className="ml-2 text-ink-3">×{formatNumber(mine.quantity, { maxDecimals: 3 })}</span>}
|
||||
{itemId == null && <span className="ml-2 text-ink-3">{t('orders.moves.lines', { count: m.items.length })}</span>}
|
||||
</span>
|
||||
<span className="text-caption text-ink-3 shrink-0">{formatDateTime(m.at, 'datetimeShort')}</span>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className="divide-y divide-line" data-testid="order-moves">
|
||||
{moves.order?.length > 0 && (
|
||||
<section>
|
||||
<h3 className="px-4 pt-3 pb-1 text-label font-semibold text-ink-2">{t('orders.moves.wholeOrder', { path: pathText(moves.order) })}</h3>
|
||||
<ul className="divide-y divide-line">{moves.order.map(m => row(m))}</ul>
|
||||
</section>
|
||||
)}
|
||||
{lines.map(([item, ms]) => (
|
||||
<section key={item.id}>
|
||||
<h3 className="px-4 pt-3 pb-1 text-label font-semibold text-ink-2">{nameOf(item)} · {pathText(ms)}</h3>
|
||||
<ul className="divide-y divide-line">{ms.map(m => row(m, item.id))}</ul>
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ import { parseNumber, useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Field, Input, cx } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { Pill } from '../overview/parts'
|
||||
import { lineAmount, lineDetails, nameOf, selectable, selectedAmount, shownLines, toggleSelected, unitOf } from './orderLogic'
|
||||
import { lineAmount, lineDetails, nameOf, pathText, selectable, selectedAmount, shownLines, toggleSelected, unitOf } from './orderLogic'
|
||||
|
||||
const STATUS_TONE = { paid: 'success', cancelled: 'danger', tabbed: 'info', closed: 'warning' }
|
||||
const EVENT_TONE = { waiter_discount: 'text-accent-ink', free_item_added: 'text-success-ink', modifier_applied: 'text-info-ink', manual_price: 'text-warning-ink' }
|
||||
|
||||
export default function OrderLines({ order, open, priceEvents, onPay, onChanged }) {
|
||||
export default function OrderLines({ order, open, priceEvents, moves = {}, onPay, onChanged }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatMoney, formatTime } = useFormat()
|
||||
const canDiscount = useCan('pricing.discounts.apply')
|
||||
@@ -70,6 +70,11 @@ export default function OrderLines({ order, open, priceEvents, onPay, onChanged
|
||||
{d.choices.length > 0 && <div className="text-caption text-ink-2">{d.choices.join(', ')}</div>}
|
||||
{d.removed.length > 0 && <div className="text-caption text-ink-2">{t('orders.lines.without', { list: d.removed.join(', ') })}</div>}
|
||||
{d.note && <div className="text-caption text-warning-ink">{d.note}</div>}
|
||||
{moves[item.id]?.length > 0 && (
|
||||
<div className="text-caption text-info-ink" data-testid="line-moved">
|
||||
↪ {t('orders.moves.linePath', { path: pathText(moves[item.id]) })}
|
||||
</div>
|
||||
)}
|
||||
<div className="text-caption text-ink-3">
|
||||
{t('orders.lines.added', { time: formatTime(item.added_at), name: item.added_by_name ?? '' })}
|
||||
{item.paid_by_name && ` · ${t('orders.lines.paidBy', { name: item.paid_by_name })}`}
|
||||
|
||||
@@ -21,12 +21,12 @@ import OrderLines from './OrderLines'
|
||||
import OrderPeople from './OrderPeople'
|
||||
import PayDialog from './PayDialog'
|
||||
import PrintProblemsCard from './PrintProblemsCard'
|
||||
import { AuditList, PriceEventList } from './OrderHistory'
|
||||
import { AuditList, MoveList, PriceEventList } from './OrderHistory'
|
||||
import { closeStep, totals, unpaidIds, venueRules } from './orderLogic'
|
||||
|
||||
const ORDER_EVENTS = ['order_updated', 'order_paid', 'order_closed', 'order_refunded', 'kds_order_updated', 'kds_item_updated']
|
||||
const STATUS_TONE = { open: 'success', partially_paid: 'info', paid: 'accent', closed: 'neutral', cancelled: 'danger' }
|
||||
const TABS = ['order', 'prices', 'history']
|
||||
const TABS = ['order', 'prices', 'moves', 'history']
|
||||
|
||||
export default function OrderPage() {
|
||||
const { orderId } = useParams()
|
||||
@@ -90,9 +90,14 @@ function OrderView({ orderId }) {
|
||||
queryKey: ['price-events', orderId], queryFn: () => client.get(`/api/pricing/events/order/${orderId}`).then(r => r.data), events: ['order_updated'],
|
||||
})
|
||||
|
||||
const { data: moves = { order: [], items: {} } } = useLiveQuery({ // 6F.4
|
||||
queryKey: ['order-moves', orderId], queryFn: () => client.get(`/api/orders/${orderId}/moves`).then(r => r.data), events: ['order_updated'],
|
||||
})
|
||||
|
||||
const refresh = () => {
|
||||
qc.invalidateQueries({ queryKey: ['order', orderId] })
|
||||
qc.invalidateQueries({ queryKey: ['price-events', orderId] })
|
||||
qc.invalidateQueries({ queryKey: ['order-moves', orderId] })
|
||||
qc.invalidateQueries({ queryKey: ['orders-active'] })
|
||||
}
|
||||
const onError = err => toast.error(errorMessage(err, t))
|
||||
@@ -155,7 +160,7 @@ function OrderView({ orderId }) {
|
||||
{tab === 'order' && (
|
||||
<div className={cx('grid gap-4 items-start', editable && 'lg:grid-cols-[minmax(0,1fr)_minmax(0,1.1fr)]')}>
|
||||
<div className="grid gap-4 min-w-0">
|
||||
<OrderLines order={order} open={editable} priceEvents={priceEvents} onChanged={refresh}
|
||||
<OrderLines order={order} open={editable} priceEvents={priceEvents} moves={moves.items} onChanged={refresh}
|
||||
onPay={(ids, amount, after) => setPaying({ ids, amount, after })} />
|
||||
<OrderPeople order={order} open={editable} staff={staff} onChanged={refresh} />
|
||||
</div>
|
||||
@@ -163,6 +168,7 @@ function OrderView({ orderId }) {
|
||||
</div>
|
||||
)}
|
||||
{tab === 'prices' && <section className="rounded-card border border-line bg-surface shadow-raised overflow-hidden"><PriceEventList events={priceEvents} /></section>}
|
||||
{tab === 'moves' && <section className="rounded-card border border-line bg-surface shadow-raised overflow-hidden"><MoveList moves={moves} order={order} /></section>}
|
||||
{tab === 'history' && <section className="rounded-card border border-line bg-surface shadow-raised overflow-hidden"><AuditList order={order} /></section>}
|
||||
|
||||
{paying && <PayDialog orderId={order.id} itemIds={paying.ids} amount={paying.amount} card={venue.card} thenClose={!!paying.thenClose}
|
||||
|
||||
@@ -104,3 +104,11 @@ export function flagsByTable(defs = [], assignments = []) {
|
||||
|
||||
/** Where a table's card goes: its order, or a new order at that table. */
|
||||
export const cardTarget = card => (card.order ? `/orders/${card.order.id}` : `/orders/new?table=${card.table.id}`)
|
||||
|
||||
/** "T2 → T5 → T7": the tables a moved order or line went through (6F.4; '—' 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(' → ')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// Reports → Moves (plan 6F.4, owner 2026-11-23): every move between tables and orders in a period:
|
||||
// a whole table moved, lines moved to another table, tables joined; from / to, who, the lines
|
||||
// with their quantities and value; counts per kind and per person; export for Excel.
|
||||
// GET /api/reports/moves (+ /export).
|
||||
import { useState } from 'react'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Dropdown, Toolbar } from '@xenia/ui'
|
||||
import client from '../../../api/client'
|
||||
import { useLiveQuery } from '../../../live/useLiveQuery'
|
||||
import { BarList } from '../kit/charts'
|
||||
import { ExportButton, Failed, Loading, Panel, ReportPage, Stat, Table } from '../kit/parts'
|
||||
import { PeriodPicker } from '../kit/Period'
|
||||
import { defaultPeriod, periodParams, periodSlug } from '../kit/reportLogic'
|
||||
|
||||
const KINDS = ['table_transfer', 'items_moved', 'orders_merged']
|
||||
|
||||
export default function MovesReport() {
|
||||
const { t } = useTranslation('manager')
|
||||
return <ReportPage title={t('reports.moves.title')} testId="report-moves"><MovesBody /></ReportPage>
|
||||
}
|
||||
|
||||
function MovesBody() {
|
||||
const { t } = useTranslation('manager')
|
||||
const fmt = useFormat()
|
||||
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||
const [kinds, setKinds] = useState([])
|
||||
const params = { ...periodParams(period), ...(kinds.length === 1 ? { kind: kinds[0] } : {}) }
|
||||
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-moves', params], queryFn: () => client.get('/api/reports/moves', { params }).then(r => r.data) })
|
||||
const rows = (data?.moves ?? []).filter(m => !kinds.length || kinds.includes(m.kind))
|
||||
const columns = [
|
||||
{ key: 'at', label: t('reports.misc.when'), render: m => fmt.formatDateTime(m.at, 'datetimeShort') },
|
||||
{ key: 'kind', label: t('reports.moves.kind'), render: m => t(`reports.moves.kinds.${m.kind}`) },
|
||||
{ key: 'from_table', label: t('reports.moves.from'), render: m => <span className="font-semibold text-ink">{m.from_table || t('reports.noTable')}</span> },
|
||||
{ key: 'to_table', label: t('reports.moves.to'), render: m => <span className="font-semibold text-ink">{m.to_table || t('reports.noTable')}</span> },
|
||||
{ key: 'items', label: t('reports.moves.lines'), sortable: false,
|
||||
render: m => <span className="text-label text-ink-2">{m.items.map(i => `${i.name ?? `#${i.item_id}`}${i.quantity != null ? ` ×${fmt.formatNumber(i.quantity, { maxDecimals: 3 })}` : ''}`).join(', ')}</span> },
|
||||
{ key: 'value', label: t('reports.misc.value'), align: 'right', render: m => fmt.formatMoney(m.value) },
|
||||
{ key: 'by', label: t('reports.moves.by'), render: m => m.by || '' },
|
||||
{ key: 'orders', label: '#', sortable: false, render: m => <span className="tabular-nums text-ink-3">#{m.from_order_id}{m.to_order_id !== m.from_order_id ? ` → #${m.to_order_id}` : ''}</span> },
|
||||
]
|
||||
return (
|
||||
<div className="grid gap-4">
|
||||
<PeriodPicker value={period} onChange={setPeriod} right={<ExportButton endpoint="/api/reports/moves/export" params={params} filename={`moves-${periodSlug(period)}.csv`} />} />
|
||||
<Toolbar>
|
||||
<Dropdown multiple value={kinds} onChange={setKinds} allLabel={t('reports.moves.allKinds')} aria-label={t('reports.moves.kind')}
|
||||
options={KINDS.map(k => ({ value: k, label: t(`reports.moves.kinds.${k}`) }))} data-testid="moves-kind" />
|
||||
</Toolbar>
|
||||
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
|
||||
<div className="grid gap-3 grid-cols-[repeat(auto-fill,minmax(12rem,1fr))]">
|
||||
<Stat label={t('reports.moves.count')} value={rows.length} testId="moves-count" />
|
||||
{KINDS.map(k => <Stat key={k} label={t(`reports.moves.kinds.${k}`)} value={data.by_kind[k] ?? 0} />)}
|
||||
</div>
|
||||
{data.by_person.length > 1 && (
|
||||
<Panel title={t('reports.misc.byWhom')}>
|
||||
<BarList format={v => fmt.formatNumber(v)} rows={data.by_person.map(p => ({ key: p.user_id ?? '—', label: p.name ?? '—', value: p.count }))} />
|
||||
</Panel>
|
||||
)}
|
||||
<Panel padded={false} title={t('reports.moves.list')} tip={t('reports.moves.listTip')}>
|
||||
<Table columns={columns} rows={rows} rowTestId="report-move" initialSort={{ key: 'at', dir: 'desc' }} limit={500} />
|
||||
</Panel>
|
||||
</>)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
// converts those routers.
|
||||
// anyPerm instead of perm: any one of these keys is enough (the media library)
|
||||
// label a key in the i18n `manager` namespace
|
||||
import { Activity, AppWindow, BadgeCheck, BarChart2, BookUser, Boxes, CalendarDays, ConciergeBell, CookingPot, CreditCard, FileText, Images, LayoutDashboard, LayoutGrid, LogIn, MonitorSmartphone, Package, PartyPopper, Percent, Plug, Printer, Receipt, Settings, ShieldCheck, ShoppingBag, ShoppingCart, StickyNote, TableProperties, Tag, Trash2, TrendingUp, Tv, UserCog, Users, Users2 } from 'lucide-react'
|
||||
import { Activity, AppWindow, ArrowRightLeft, BadgeCheck, BarChart2, BookUser, Boxes, CalendarDays, ConciergeBell, CookingPot, CreditCard, FileText, Images, LayoutDashboard, LayoutGrid, LogIn, MonitorSmartphone, Package, PartyPopper, Percent, Plug, Printer, Receipt, Settings, ShieldCheck, ShoppingBag, ShoppingCart, StickyNote, TableProperties, Tag, Trash2, TrendingUp, Tv, UserCog, Users, Users2 } from 'lucide-react'
|
||||
|
||||
const DASH = 'core.dashboard.access'
|
||||
// The media library: whoever manages something that shows pictures (routers/media.py MANAGE)
|
||||
@@ -90,6 +90,7 @@ export const NAV = [
|
||||
{ to: '/reports/expenses', icon: FileText, label: 'nav.reportsExpenses', module: 'reports', perm: 'reports.view' },
|
||||
{ to: '/reports/technical', icon: Printer, label: 'nav.reportsTechnical', module: 'reports', perm: 'reports.view' },
|
||||
{ to: '/reports/misc', icon: Tag, label: 'nav.reportsMisc', module: 'reports', perm: 'reports.view' },
|
||||
{ to: '/reports/moves', icon: ArrowRightLeft, label: 'nav.reportsMoves', module: 'reports', perm: 'reports.view' },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user