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
+16
View File
@@ -737,6 +737,20 @@ try {
let notesNow = []
for (let i = 0; i < 30 && !notesNow.includes('E2E: well done'); i++) { await sleep(150); notesNow = JSON.parse(await settingValue2('orders.quick_notes') || '[]') }
r.check(`${st6} Operation: a quick note added`, notesNow.includes('E2E: well done'), JSON.stringify(notesNow))
// 6F.3: prices changed by hand: the venue's switch, then the reason and its quick reasons
await page.getByTestId('setting-orders.price_change').selectOption('before_sending')
let pcMode = ''
for (let i = 0; i < 30 && pcMode !== 'before_sending'; i++) { await sleep(150); pcMode = await settingValue2('orders.price_change') }
await page.getByTestId('settings-price-changes').getByRole('switch').first().click()
await page.getByTestId('price-reason-new').fill('E2E: birthday')
await page.getByTestId('price-reason-add').click()
let reasonsNow = []
for (let i = 0; i < 30 && !reasonsNow.includes('E2E: birthday'); i++) { await sleep(150); reasonsNow = JSON.parse(await settingValue2('orders.price_change_reasons') || '[]') }
r.check(`${st6} Operation: prices by hand "before sending only", a reason asked, a quick reason added`,
pcMode === 'before_sending' && await settingValue2('orders.price_change_reason') === 'true' && reasonsNow.includes('E2E: birthday'))
await page.getByTestId('setting-orders.price_change').selectOption('anytime')
await page.getByTestId('settings-price-changes').getByRole('switch').first().click()
await sleep(500)
await page.getByTestId('flag-new').click()
await page.getByTestId('flag-save').click()
r.check(`${st6} a table flag needs a name`, (await page.getByTestId('flag-dialog').textContent()).includes('Enter a name'))
@@ -1421,6 +1435,8 @@ try {
await opens('/reports/misc', 'cancellations-count', 'Cancellations')
await page.getByTestId('report-tab-discounts').click()
r.check(`${rp} Discounts opens`, await page.getByTestId('report-period').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
await page.getByTestId('report-tab-price-changes').click()
r.check(`${rp} Price changes opens (6F.3)`, await page.getByTestId('price-changes-count').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
await opens('/reports/technical', 'printing-total', 'Technical → Printing')
await opens('/reports/prep-zones', 'report-period', 'Prep zones')
await opens('/reports/expenses', 'expenses-total', 'Expenses')
+44
View File
@@ -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 } })