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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user