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
+54 -10
View File
@@ -16,6 +16,10 @@ import { TransferIcon, MergeIcon, FlagsIcon, WaiterIcon, PrintIcon } from '../co
import usePaymentSettingsStore from '../store/paymentSettingsStore'
import useTableViewStore from '../store/tableViewStore'
import { parseNumber, useTranslation } from '@xenia/i18n'
import PriceReason from '../components/PriceReason'
import { priceReasonText } from '../logic/priceRules'
import PriceHistory from '../components/PriceHistory'
import { usePriceRules } from '../hooks/usePriceRules'
import { fade } from '../logic/colour'
import SeatsHint from '../components/SeatsHint'
@@ -119,8 +123,10 @@ function SplitModal({ item, onConfirm, onClose }) {
// ─── Price adjust modal ───────────────────────────────────────────────────────
function PriceAdjustModal({ item, onConfirm, onClose }) {
function PriceAdjustModal({ item, rules, error, onConfirm, onClose }) {
const { t } = useTranslation('waiter')
const [reason, setReason] = useState({ choice: '', other: '' }) // 6F.3
const [tried, setTried] = useState(false)
const basePrice = item.unit_price ?? 0
const [adj, setAdj] = useState(item.price_adjustment ?? 0)
const [editing, setEditing] = useState(false)
@@ -225,6 +231,13 @@ function PriceAdjustModal({ item, onConfirm, onClose }) {
))}
</div>
{rules.reasonRequired && adj !== (item.price_adjustment ?? 0) && (
<div style={{ marginBottom: 14 }}>
<PriceReason rules={rules} state={reason} onChange={setReason} missing={tried && !priceReasonText(rules, t, reason)} />
</div>
)}
{error && <p role="alert" style={{ color: 'var(--x-danger)', fontSize: 13, textAlign: 'center', margin: '0 0 10px' }}>{error}</p>}
{/* Reset */}
{adj !== 0 && (
<button
@@ -241,7 +254,7 @@ function PriceAdjustModal({ item, onConfirm, onClose }) {
<div style={{ display: 'flex', gap: 10 }}>
<button className="btn btn--secondary" style={{ flex: 1 }} onClick={onClose}>{t('common.cancel')}</button>
<button className="btn btn--primary" style={{ flex: 1 }} onClick={() => onConfirm(adj)}>
<button className="btn btn--primary" style={{ flex: 1 }} onClick={() => (() => { const r = priceReasonText(rules, t, reason); if (adj !== (item.price_adjustment ?? 0) && rules.reasonRequired && !r) { setTried(true); return } onConfirm(adj, r) })()}>
{t('common.apply')}
</button>
</div>
@@ -252,7 +265,7 @@ function PriceAdjustModal({ item, onConfirm, onClose }) {
// ─── Item action modal (long-press) ──────────────────────────────────────────
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, onCombine, canCancel, cancelNeedsApproval, priceAdjAllowed, priceNeedsApproval, canMove, onAdjustPrice, onClose }) {
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, onCombine, canCancel, cancelNeedsApproval, priceAdjAllowed, priceNeedsApproval, canMove, onAdjustPrice, canSeePriceHistory, onPriceHistory, onClose }) {
const { t } = useTranslation('waiter')
const { items, singleStacked, multiSelect } = target
const label = multiSelect
@@ -260,6 +273,22 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
: items[0]?.product?.name || `#${items[0]?.product_id}`
const actionRows = [
// 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',
color: 'var(--x-warning)',
iconBg: 'rgb(var(--x-warning-rgb) / 0.15)',
label: t('price.history'),
sub: t('price.historySub'),
icon: (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="9" stroke="var(--x-warning)" strokeWidth="2" />
<path d="M12 7v5l3 2" stroke="var(--x-warning)" strokeWidth="2" strokeLinecap="round" />
</svg>
),
onClick: onPriceHistory,
enabled: true,
}] : []),
...(!multiSelect && priceAdjAllowed ? [{
key: 'adjust_price',
color: 'var(--x-warning)',
@@ -1097,10 +1126,15 @@ export default function TableDetailPage() {
// manager's PIN on the phone, the approval dialog opens by itself) or 'no'
const cancelAccess = useAllowed('ordering.orders.cancel')
const revertAccess = useAllowed('ordering.payments.revert')
const priceAccess = useAllowed('ordering.prices.modify')
// a sent line's price (6F.3): its own key, and the venue allows changes after sending
const priceAccess = useAllowed('ordering.prices.modify_sent')
const priceRulesNow = usePriceRules()
const seesPriceChanges = useCan('ordering.prices.view_changes')
const [priceError, setPriceError] = useState('')
const [historyItem, setHistoryItem] = useState(null)
const canCancel = cancelAccess !== 'no'
const revertAllowed = revertAccess !== 'no'
const priceAdjAllowed = priceAccess !== 'no'
const priceAdjAllowed = priceAccess !== 'no' && priceRulesNow.afterSending
const canDiscount = useCan('pricing.discounts.apply')
const canPay = useCan('ordering.orders.close')
const canMove = useCan('ordering.orders.open')
@@ -2201,6 +2235,12 @@ export default function TableDetailPage() {
setItemActionTarget(null)
setPriceAdjustItem(item)
}}
canSeePriceHistory={seesPriceChanges && !isOffline}
onPriceHistory={() => {
const item = itemActionTarget.items[0]
setItemActionTarget(null)
setHistoryItem(item)
}}
onCancel={() => {
const ids = itemActionTarget.items.map(i => i.id)
setItemActionTarget(null)
@@ -2226,22 +2266,26 @@ export default function TableDetailPage() {
{priceAdjustItem && (
<PriceAdjustModal
item={priceAdjustItem}
onConfirm={async (adj) => {
rules={priceRulesNow}
error={priceError}
onConfirm={async (adj, reason) => {
try {
setPriceError('')
await client.patch(`/api/orders/${order.id}/items/${priceAdjustItem.id}/price-adjust`, {
price_adjustment: adj,
price_adjustment: adj, reason: reason || undefined,
})
setPriceAdjustItem(null)
await load()
} catch (err) {
console.error('[price-adjust] failed:', err)
setPriceAdjustItem(null)
setPriceError(apiError(err, t('detail.err.price'))) // stays open: the reason or a manager's PIN
}
}}
onClose={() => setPriceAdjustItem(null)}
onClose={() => { setPriceAdjustItem(null); setPriceError('') }}
/>
)}
{historyItem && <PriceHistory orderId={order.id} item={historyItem} onClose={() => setHistoryItem(null)} />}
{/* Cancel confirmation */}
{cancelConfirm && (
<CancelConfirmModal