feat(backend,waiter,manager): prices changed by hand are on the record

Owner 2026-11-23 (plan 6F.3). services/price_changes.py: the venue's switch orders.price_change
(off | before_sending | anytime, default anytime as before), orders.price_change_reason and its
quick reasons; keys ordering.prices.modify (the cart), new modify_sent (a sent or served line) and
view_changes (who sees them). Every by-hand price (waiter cart, a sent line, the counter's %
discount) writes a manual_price PriceEventLog row (before, after, quantity, who, approving manager,
stage, reason) plus a PRICE_CHANGED audit row; before, the sent-line change overwrote the price with
no record. Alembic 0047: event columns; modify_sent for everyone holding modify (and the venues'
role overrides), view_changes for owners and store managers.
Waiter: the reason picker when the venue asks, a sent line's price on modify_sent and the venue's
switch, the line's price history. Manager: Settings -> Operation 'Prices changed by hand', the
changes on the order's lines and history, Reports -> Cancellations, discounts and price changes
(+ export). Counter: no discount when the venue turned price changes off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 07:41:43 +02:00
co-authored by Claude Opus 5.5
parent e3f4f3eeee
commit f87f9ff23c
40 changed files with 1044 additions and 73 deletions
@@ -2,6 +2,7 @@
// cancelled line (what, how much, who sent it, who cancelled it, why) and every discount given
// (on what, how much, by whom, why), with totals per person; exports for Excel.
import { useState } from 'react'
import { useCan } from '@xenia/access'
import { useFormat, useTranslation } from '@xenia/i18n'
import client from '../../../api/client'
import { useLiveQuery } from '../../../live/useLiveQuery'
@@ -12,9 +13,11 @@ import { defaultPeriod, periodParams, periodSlug } from '../kit/reportLogic'
export default function MiscReport() {
const { t } = useTranslation('manager')
const seesChanges = useCan('ordering.prices.view_changes')
const tabs = [
{ id: 'cancellations', label: t('reports.misc.cancellations'), Component: CancellationsTab },
{ id: 'discounts', label: t('reports.misc.discounts'), Component: DiscountsTab },
...(seesChanges ? [{ id: 'price-changes', label: t('reports.misc.priceChanges'), Component: PriceChangesTab }] : []),
]
return <ReportPage title={t('reports.misc.title')} tabs={tabs} testId="report-misc" />
}
@@ -102,3 +105,46 @@ function DiscountsTab() {
</div>
)
}
/** Prices changed by hand (6F.3): each change, before → after, its value for the line's quantity,
* where (cart / sent / served), who, the approving manager, why; totals per person. */
function PriceChangesTab() {
const { t } = useTranslation('manager')
const fmt = useFormat()
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
const params = periodParams(period)
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-price-changes', params], queryFn: () => client.get('/api/reports/price-changes', { params }).then(r => r.data) })
const rows = data?.changes ?? []
const columns = [
{ key: 'at', label: t('reports.misc.when'), render: c => fmt.formatDateTime(c.at, 'datetimeShort') },
{ key: 'product_name', label: t('reports.prod.product'), render: c => <span className="font-semibold text-ink">{c.product_name}</span> },
{ key: 'table_name', label: t('reports.place'), render: c => c.table_name || t('reports.noTable') },
{ key: 'before', label: t('reports.misc.priceWas'), align: 'right', render: c => fmt.formatMoney(c.before) },
{ key: 'after', label: t('reports.misc.priceNow'), align: 'right', render: c => fmt.formatMoney(c.after) },
{ key: 'value', label: t('reports.misc.value'), align: 'right', render: c => <span className={c.value < 0 ? 'font-semibold text-danger-ink' : 'font-semibold text-success-ink'}>{fmt.formatMoney(c.value, { signDisplay: 'exceptZero' })}</span> },
{ key: 'stage', label: t('reports.misc.stage'), render: c => (c.stage ? t(`orders.history.stage.${c.stage}`) : '') },
{ key: 'by', label: t('reports.misc.changedBy'), render: c => c.by || '' },
{ key: 'approved_by', label: t('reports.misc.approvedBy'), render: c => c.approved_by || '' },
{ key: 'reason', label: t('reports.misc.reason'), render: c => c.reason || '' },
]
return (
<div className="grid gap-4">
<PeriodPicker value={period} onChange={setPeriod} right={<ExportButton endpoint="/api/reports/price-changes/export" params={params} filename={`price-changes-${periodSlug(period)}.csv`} />} />
{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.misc.changes')} value={data.count} testId="price-changes-count" />
<Stat label={t('reports.misc.changesValue')} tone={data.total_value < 0 ? 'danger' : 'success'} value={fmt.formatMoney(data.total_value, { signDisplay: 'exceptZero' })} tip={t('reports.misc.changesValueTip')} />
</div>
{data.by_person.length > 1 && (
<Panel title={t('reports.misc.byWhom')}>
<BarList format={v => fmt.formatMoney(v, { signDisplay: 'exceptZero' })} rows={data.by_person.map(p => ({ key: p.user_id ?? '—', label: p.name ?? '—', value: p.total_value, sub: t('reports.misc.changesCount', { count: p.count }) }))} />
</Panel>
)}
<Panel padded={false} title={t('reports.misc.priceChanges')}>
<Table columns={columns} rows={rows} rowTestId="report-price-change" initialSort={{ key: 'at', dir: 'desc' }} limit={500} />
</Panel>
</>)}
</div>
)
}