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>
28 lines
1.7 KiB
JavaScript
28 lines
1.7 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { test } from 'node:test'
|
|
import { priceRules } from '../src/logic/priceRules.js'
|
|
|
|
const set = o => Object.fromEntries(Object.entries(o).map(([k, value]) => [k, { value }]))
|
|
|
|
test('the venue rules for prices changed by hand (6F.3)', () => {
|
|
assert.deepEqual(priceRules(null), { mode: 'anytime', inCart: true, afterSending: true, reasonRequired: false, reasons: [] })
|
|
const off = priceRules(set({ 'orders.price_change': 'off' }))
|
|
assert.equal(off.inCart, false); assert.equal(off.afterSending, false)
|
|
const cart = priceRules(set({ 'orders.price_change': 'before_sending', 'orders.price_change_reason': 'true' }))
|
|
assert.equal(cart.inCart, true); assert.equal(cart.afterSending, false); assert.equal(cart.reasonRequired, true)
|
|
assert.deepEqual(priceRules(set({ 'orders.price_change_reasons': '[" Friend ", "", 3]' })).reasons, ['Friend'])
|
|
assert.deepEqual(priceRules(set({ 'orders.price_change_reasons': 'not json' })).reasons, [])
|
|
assert.equal(priceRules(set({ 'orders.price_change': 'weird' })).mode, 'anytime')
|
|
})
|
|
|
|
test('the reason sent: a quick reason, a typed one, or none', async () => {
|
|
const { priceReasonText } = await import('../src/logic/priceRules.js')
|
|
const t = k => `T:${k}`
|
|
const builtIn = priceRules(null)
|
|
assert.equal(priceReasonText(builtIn, t, { choice: 'regular', other: '' }), 'T:price.reasons.regular')
|
|
assert.equal(priceReasonText(builtIn, t, { choice: 'other', other: ' burnt ' }), 'burnt')
|
|
assert.equal(priceReasonText(builtIn, t, { choice: '', other: 'x' }), '')
|
|
const own = priceRules(set({ 'orders.price_change_reasons': '["Friend"]' }))
|
|
assert.equal(priceReasonText(own, t, { choice: 'v0' }), 'Friend')
|
|
})
|