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:
@@ -303,6 +303,50 @@ try {
|
||||
await a.getByTestId('menu-language-en').click()
|
||||
await waitFor(async () => (await navText()).includes('Tables'), 8000, 300)
|
||||
|
||||
// ── 6F.3: a sent line's price changed by hand, with the reason the venue asks for ──────
|
||||
{
|
||||
const mariaKeys = (await api('GET', `/api/waiters/${maria.id}/permissions`, { token: boss })).keys
|
||||
await api('PUT', `/api/waiters/${maria.id}/permissions`, { token: boss,
|
||||
body: { keys: [...new Set([...mariaKeys, 'ordering.prices.modify_sent', 'ordering.prices.view_changes'])] } })
|
||||
await setting(boss, 'orders.price_change_reason', 'true')
|
||||
const tp = free.find(t => t.id !== t4.id && t.id !== t5.id && t.id !== (free.find(x => x.id !== t4.id && x.id !== t5.id)?.id)) || free[free.length - 1]
|
||||
const op = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: tp.id } })
|
||||
await api('POST', `/api/orders/${op.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 1 }] } })
|
||||
await a.goto(`${APP}/tables/${tp.id}`)
|
||||
await a.reload() // the keys were changed after sign-in: the bootstrap comes again
|
||||
await a.locator('.order-item').first().waitFor({ timeout: 10_000 })
|
||||
await a.locator('.order-item').first().click()
|
||||
await a.getByRole('button', { name: 'ACTIONS', exact: true }).last().click()
|
||||
await a.getByText('Change the price').first().click({ timeout: 10_000 })
|
||||
await a.getByRole('button', { name: '-1 €' }).first().click()
|
||||
r.check('6F.3: the venue asks why: the reason picker shows with a changed price', await shown(a, 'price-reason', 5000))
|
||||
await a.getByRole('button', { name: 'Apply' }).click()
|
||||
await sleep(600)
|
||||
const unchanged = (await api('GET', `/api/orders/${op.id}`, { token: boss })).items[0].price_adjustment || 0
|
||||
r.check('6F.3: without a reason nothing is saved', unchanged === 0 && await a.getByText('Say why the price changes').isVisible().catch(() => false))
|
||||
await a.getByText('Regular customer').first().click()
|
||||
await a.getByRole('button', { name: 'Apply' }).click()
|
||||
const changed = await waitFor(async () => {
|
||||
const ev = (await api('GET', `/api/orders/${op.id}/price-changes`, { token: boss }))
|
||||
return ev.length === 1 && ev[0]
|
||||
}, 10_000, 500)
|
||||
r.check('6F.3: saved with its reason, who and the stage', !!changed && Math.abs(changed.after - (changed.before - 1)) < 0.001
|
||||
&& changed.reason === 'Regular customer' && changed.stage === 'sent' && changed.by_id === maria.id, JSON.stringify(changed))
|
||||
await a.goto(`${APP}/tables/${tp.id}`)
|
||||
await a.locator('.order-item').first().waitFor({ timeout: 10_000 })
|
||||
await a.locator('.order-item').first().click()
|
||||
await a.getByRole('button', { name: 'ACTIONS', exact: true }).last().click()
|
||||
await a.getByText('Price history').first().click({ timeout: 10_000 })
|
||||
r.check('6F.3: the price history on the phone (who, from → to, why)', await shown(a, 'price-history-row', 8000)
|
||||
&& (await a.getByTestId('price-history-row').first().textContent()).includes('Regular customer'))
|
||||
await a.keyboard.press('Escape').catch(() => {})
|
||||
await setting(boss, 'orders.price_change_reason', 'false')
|
||||
await api('PUT', `/api/waiters/${maria.id}/permissions`, { token: boss, body: { keys: mariaKeys } })
|
||||
await setting(boss, 'orders.close_with_unpaid', 'true')
|
||||
await api('POST', `/api/orders/${op.id}/close`, { token: boss })
|
||||
await setting(boss, 'orders.close_with_unpaid', 'false')
|
||||
}
|
||||
|
||||
// ── 4.8: the owner's choices: combine lines, close with unpaid items, seats ─────────
|
||||
const t6 = free.find(t => t.id !== t4.id && t.id !== t5.id)
|
||||
const o6 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t6.id } })
|
||||
|
||||
Reference in New Issue
Block a user