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:
@@ -4,6 +4,9 @@ import useWaiterFavoritesStore from '../store/waiterFavoritesStore'
|
||||
import { assetUrl } from '../config/server'
|
||||
import { money } from '../i18n'
|
||||
import { parseNumber, useTranslation } from '@xenia/i18n'
|
||||
import PriceReason from './PriceReason'
|
||||
import { priceReasonText } from '../logic/priceRules'
|
||||
import { usePriceRules } from '../hooks/usePriceRules'
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -815,7 +818,7 @@ function QuantityTab({ unitCfg, qty, setQty }) {
|
||||
|
||||
const PRICE_DELTAS = [-5, -3, -2, -1, -0.5, -0.2, +0.2, +0.5, +1, +2, +3, +5]
|
||||
|
||||
function PriceAdjustTab({ basePrice, priceAdj, setPriceAdj }) {
|
||||
function PriceAdjustTab({ basePrice, priceAdj, setPriceAdj, rules, reason, setReason, reasonMissing }) {
|
||||
const { t } = useTranslation('waiter')
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [rawInput, setRawInput] = useState('')
|
||||
@@ -904,6 +907,8 @@ function PriceAdjustTab({ basePrice, priceAdj, setPriceAdj }) {
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{/* 6F.3: the venue asks why a price changes */}
|
||||
{rules?.reasonRequired && priceAdj !== 0 && <PriceReason rules={rules} state={reason} onChange={setReason} missing={reasonMissing} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1069,7 +1074,9 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
|
||||
const itemFavorites = useWaiterFavoritesStore(s => s.itemFavorites)
|
||||
// A price set before sending needs the key itself (plan 4.3); the manager-approval path for
|
||||
// it comes with server-priced orders (4.4). After sending, the item's actions offer it.
|
||||
const priceAdjAllowed = useCan('ordering.prices.modify')
|
||||
// 6F.3: and the venue allows prices typed before sending (orders.price_change)
|
||||
const priceRulesNow = usePriceRules()
|
||||
const priceAdjAllowed = useCan('ordering.prices.modify') && priceRulesNow.inCart
|
||||
|
||||
const preferenceSets = product?.preference_sets || []
|
||||
const quickOptions = product?.quick_options || []
|
||||
@@ -1136,6 +1143,7 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
|
||||
const [sharedSubs, setSharedSubs] = useState({})
|
||||
const [note, setNote] = useState('')
|
||||
const [priceAdj, setPriceAdj] = useState(0)
|
||||
const [priceReason, setPriceReason] = useState({ choice: '', other: '' }) // 6F.3
|
||||
const [addAttempted, setAddAttempted] = useState(false)
|
||||
const [courseId, setCourseId] = useState(initialState?.courseId ?? null)
|
||||
|
||||
@@ -1153,6 +1161,7 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
|
||||
setSharedSubs(initialState.sharedSubs ?? base.sharedSubs)
|
||||
setNote(initialState.note ?? '')
|
||||
setPriceAdj(initialState.priceAdj ?? 0)
|
||||
setPriceReason(initialState.priceReason ?? { choice: '', other: '' })
|
||||
setCourseId(initialState.courseId ?? null)
|
||||
} else {
|
||||
setQty(isDecimal ? (unitCfg?.presets[0] ?? 0.1) : 1)
|
||||
@@ -1164,6 +1173,7 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
|
||||
setSharedSubs(base.sharedSubs)
|
||||
setNote('')
|
||||
setPriceAdj(0)
|
||||
setPriceReason({ choice: '', other: '' })
|
||||
setCourseId(null)
|
||||
}
|
||||
setExpandedExtra(null)
|
||||
@@ -1265,6 +1275,12 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
|
||||
const favTabAlert = favHasIncompletePref && (addAttempted || prefsHasMandatory)
|
||||
|
||||
function handleAdd() {
|
||||
const reasonTxt = priceAdj !== 0 ? priceReasonText(priceRulesNow, t, priceReason) : ''
|
||||
if (priceAdj !== 0 && priceRulesNow.reasonRequired && !reasonTxt) { // 6F.3: why the price changes
|
||||
setAddAttempted(true)
|
||||
setActiveTab('price_adjust')
|
||||
return
|
||||
}
|
||||
if (!canAdd) {
|
||||
setAddAttempted(true)
|
||||
if (!allPrefsOk) {
|
||||
@@ -1341,8 +1357,9 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
|
||||
removed_ingredients: removedNames,
|
||||
notes: note,
|
||||
price_adjustment: priceAdj !== 0 ? priceAdj : undefined,
|
||||
price_reason: reasonTxt || undefined,
|
||||
course_id: courseId ?? undefined,
|
||||
_drawerState: { qty, quickState, extrasState, removedState, prefs, subChoices, sharedSubs, note, priceAdj, courseId },
|
||||
_drawerState: { qty, quickState, extrasState, removedState, prefs, subChoices, sharedSubs, note, priceAdj, priceReason, courseId },
|
||||
})
|
||||
onClose()
|
||||
}
|
||||
@@ -1507,7 +1524,9 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
|
||||
{activeTab === 'quantity' && isDecimal && <QuantityTab unitCfg={unitCfg} qty={qty} setQty={setQty} />}
|
||||
{activeTab === 'courses' && courses?.length > 0 && <CoursesTab courses={courses} courseId={courseId} setCourseId={setCourseId} />}
|
||||
{activeTab === 'notes' && <NotesTab note={note} setNote={setNote} quickNotes={quickNotes ?? undefined} />}
|
||||
{activeTab === 'price_adjust' && <PriceAdjustTab basePrice={product.base_price} priceAdj={priceAdj} setPriceAdj={setPriceAdj} />}
|
||||
{activeTab === 'price_adjust' && <PriceAdjustTab basePrice={product.base_price} priceAdj={priceAdj} setPriceAdj={setPriceAdj}
|
||||
rules={priceRulesNow} reason={priceReason} setReason={setPriceReason}
|
||||
reasonMissing={addAttempted && priceRulesNow.reasonRequired && !priceReasonText(priceRulesNow, t, priceReason)} />}
|
||||
{activeTab === 'summary' && <SummaryTab product={product} summaryLines={summaryLines} note={note} onJumpTab={setActiveTab} />}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// A line's price changes (plan 6F.3), for people with ordering.prices.view_changes: each change,
|
||||
// from → to, where it happened (before sending / after sending / after serving), who, the
|
||||
// manager who approved it, why. GET /api/orders/{id}/price-changes.
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import client from '../api/client'
|
||||
import { apiError } from '../api/errors'
|
||||
|
||||
export default function PriceHistory({ orderId, item, onClose }) {
|
||||
const { t } = useTranslation('waiter')
|
||||
const { formatDateTime, formatMoney } = useFormat()
|
||||
const [rows, setRows] = useState(null)
|
||||
const [error, setError] = useState('')
|
||||
useEffect(() => {
|
||||
let alive = true
|
||||
client.get(`/api/orders/${orderId}/price-changes`)
|
||||
.then(r => { if (alive) setRows(r.data.filter(c => c.item_id === item.id)) })
|
||||
.catch(err => { if (alive) setError(apiError(err, t('price.historyFailed'))) })
|
||||
return () => { alive = false }
|
||||
}, [orderId, item.id, t])
|
||||
return (
|
||||
<div className="modal-overlay" onClick={onClose}>
|
||||
<div className="modal-sheet" onClick={e => e.stopPropagation()} data-testid="price-history">
|
||||
<div className="modal-handle" />
|
||||
<h2 className="modal-title">{t('price.history')}</h2>
|
||||
<p style={{ textAlign: 'center', color: 'var(--muted)', fontSize: 13, margin: '0 0 14px' }}>{item.product_name || item.product?.name}</p>
|
||||
{error && <p role="alert" style={{ color: 'var(--x-danger)', fontSize: 13, textAlign: 'center' }}>{error}</p>}
|
||||
{!error && rows === null && <p style={{ textAlign: 'center', color: 'var(--muted)' }}>…</p>}
|
||||
{rows?.length === 0 && <p style={{ textAlign: 'center', color: 'var(--muted)', fontSize: 13 }}>{t('price.historyNone')}</p>}
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{rows?.map(c => (
|
||||
<div key={c.id} data-testid="price-history-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>{formatMoney(c.before)} → {formatMoney(c.after)}</span>
|
||||
<span style={{ color: c.delta < 0 ? 'var(--x-danger)' : 'var(--x-success)' }}>{formatMoney(c.delta, { signDisplay: 'exceptZero' })}</span>
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--muted)' }}>
|
||||
{formatDateTime(c.at, 'datetimeShort')} · {t(`price.stage.${c.stage || 'cart'}`)}{c.by ? ` · ${c.by}` : ''}
|
||||
{c.approved_by ? ` · ${t('price.approvedBy', { name: c.approved_by })}` : ''}
|
||||
</div>
|
||||
{c.reason && <div style={{ fontSize: 13 }}>{c.reason}</div>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<button className="btn btn--secondary" style={{ width: '100%', marginTop: 16 }} onClick={onClose}>{t('common.close')}</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Why a price changes (plan 6F.3): the venue's quick reasons (or the built-in ones) or a typed one.
|
||||
// Shown when the venue asks for a reason; the parent keeps { choice, other } and sends
|
||||
// priceReasonText(rules, t, state) (logic/priceRules.js).
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { ReasonPicker } from '@xenia/ui'
|
||||
import { priceReasonOptions } from '../logic/priceRules'
|
||||
|
||||
export default function PriceReason({ rules, state, onChange, missing = false }) {
|
||||
const { t } = useTranslation('waiter')
|
||||
return (
|
||||
<div style={{ display: 'grid', gap: 8 }} data-testid="price-reason">
|
||||
<div style={{ fontSize: 13, fontWeight: 700, color: missing ? 'var(--x-danger)' : 'var(--muted)' }}>
|
||||
{missing ? t('price.reasonMissing') : t('price.reason')}
|
||||
</div>
|
||||
<ReasonPicker options={priceReasonOptions(rules, t)} value={state.choice} onChange={choice => onChange({ ...state, choice })}
|
||||
other={state.other} onOther={other => onChange({ ...state, other })} otherLabel={t('price.reasons.other')}
|
||||
ariaLabel={t('price.reason')} testIdPrefix="price-reason" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user