feat(connect): the site side of online orders: fee line, customer's time, price check
Plan phase 3S, step S.5. - Pull: an online order keeps the customer's time (orders.requested_for, None = as soon as possible) and delivery area; quick options are stored in the site's entry shape; items get their cost snapshot. - The delivery fee is its own order line: a system product (products.system_key "delivery_fee", lifecycle "system", sold nowhere; services/system_products.py), created on first use in the venue's language with the VAT group most products use. Added printed and served, so kitchen tickets and the KDS never see it; paid at the counter with the items, counted in the shift, on the fiscal receipt with its VAT group. Never listed in the catalogue (products list, export, edit endpoints → 404) and never added by hand. - Price check (services/online_check.py): each line priced as the snapshot prices it, at the order's time, and the fee through the same engine with the site's rules and the cloud's area id; differences kept on orders.online_price_diff and shown. The customer pays what the cloud charged. - Counter: time chip (or as soon as possible), area, fee line, price warning; takeaway is its own kind (was shown as "at the venue") and finishes as "collected". KDS cards show the online reference and the time; kitchen tickets print the reference, the type and the time. - Manager: Online ordering → "The fee on the receipt" (name, VAT group; PUT /api/connect/fees/fee-product, fees.vat_group_unknown); the online orders page shows the time, area and price warning. - Migration 0019. Tests: tests/test_online_site_side.py (6), terminal unit test, e2e (terminal: fee, time, warning, paid in full; manager: fee line settings). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -562,6 +562,17 @@ try {
|
||||
await page.getByTestId('test-run').click()
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid="test-result"]')?.dataset.refused, null, { timeout: 5000 }).catch(() => {})
|
||||
r.check('fees: …a postcode outside the areas is refused', await page.getByTestId('test-result').getAttribute('data-refused') === 'area_not_served')
|
||||
// S.5: the fee's line on the bill and the receipt (a system product, never in the catalogue)
|
||||
await page.getByTestId('fee-product-name').fill('Delivery')
|
||||
await page.getByTestId('fee-product-vat').fill('2')
|
||||
await page.getByTestId('fee-product-save').click()
|
||||
let feeProduct = null
|
||||
for (let i = 0; i < 30 && feeProduct?.name !== 'Delivery'; i++) {
|
||||
feeProduct = (await api('GET', '/api/connect/fees', { token: boss })).fee_product
|
||||
if (feeProduct?.name !== 'Delivery') await sleep(100)
|
||||
}
|
||||
r.check('fees: the fee line\'s name and VAT group are saved', feeProduct?.name === 'Delivery' && feeProduct?.vat_group_id === 2, JSON.stringify(feeProduct))
|
||||
r.check('fees: …and it never shows in the products list', !(await api('GET', '/api/products/?all=true', { token: boss })).some(p => p.id === feeProduct?.id))
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-fees.png'), fullPage: true })
|
||||
|
||||
await page.goto(`${APP}/settings`)
|
||||
|
||||
@@ -157,7 +157,7 @@ try {
|
||||
const pending = await call('GET', `/api/orders/pending/${numeric}`, { headers: siteH })
|
||||
const delivery = pending.find(o => o.public_ref === 'ORD-0002')
|
||||
r.check('the site receives it at the cloud\'s prices with the area', delivery && delivery.total === 9 && delivery.delivery_fee === 2
|
||||
&& delivery.delivery_area === 'Centre' && delivery.sales_point === 'online_delivery', JSON.stringify(delivery))
|
||||
&& delivery.delivery_area === 'Centre' && delivery.delivery_area_id === 1 && delivery.sales_point === 'online_delivery', JSON.stringify(delivery))
|
||||
for (const status of ['accepted', 'preparing', 'out_for_delivery', 'delivered']) {
|
||||
await call('PATCH', `/api/orders/${delivery.id}/status`, { headers: siteH, body: { status } })
|
||||
const seen = await page.waitForFunction(st => document.querySelector('[data-testid="track"]')?.dataset.status === st, status, { timeout: 15_000 }).then(() => true).catch(() => false)
|
||||
|
||||
+20
-7
@@ -524,14 +524,18 @@ try {
|
||||
await api('PUT', '/api/platform/modules/connect_menu', { token: boss, body: { enabled: true } })
|
||||
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
|
||||
r.check('3.3d: online orders on → the counter gets an Online mode', await shown(page, 'mode-online', 10_000))
|
||||
const cloudOrder = (id, type, name) => ({
|
||||
// S.5: a delivery comes with its fee (€2.50 here, a line of its own), the customer's time and area
|
||||
const FEE = 2.5
|
||||
const cloudOrder = (id, type, name, fee = 0, extra = {}) => ({
|
||||
id, public_ref: `ORD-${String(id).padStart(4, '0')}`, order_type: type, customer_name: name, customer_phone: '6900000000',
|
||||
customer_address: type === 'delivery' ? 'Main square 3' : null, customer_notes: 'Ring twice', status: 'pending_acceptance',
|
||||
items_json: JSON.stringify([{ product_id: simple.id, name: simple.name, quantity: 2, unit_price: simple.price, options: [] }]),
|
||||
subtotal: 2 * simple.price, delivery_fee: 0, total: 2 * simple.price, created_at: new Date().toISOString(),
|
||||
subtotal: 2 * simple.price, delivery_fee: fee, total: 2 * simple.price + fee, created_at: new Date().toISOString(), ...extra,
|
||||
})
|
||||
const chimesBefore = Number(await page.getByTestId('pos-screen').getAttribute('data-chimes'))
|
||||
cloud.queue.push(cloudOrder(41, 'delivery', 'Nikos Online'))
|
||||
const forTime = new Date(Date.now() + 2 * 3600_000)
|
||||
forTime.setUTCMinutes(30, 0, 0)
|
||||
cloud.queue.push(cloudOrder(41, 'delivery', 'Nikos Online', FEE, { requested_for: forTime.toISOString(), delivery_area: 'Centre', delivery_area_id: 1 }))
|
||||
const rang = await page.waitForFunction(n => Number(document.querySelector('[data-testid="pos-screen"]')?.dataset.chimes) > n, chimesBefore, { timeout: 15_000 })
|
||||
.then(() => true).catch(() => false)
|
||||
const badged = await page.waitForFunction(() => document.querySelector('[data-testid="mode-online"]')?.dataset.badge === '1', null, { timeout: 5000 })
|
||||
@@ -548,8 +552,14 @@ try {
|
||||
r.check('3.3d: the order shows the customer (phone, address, note) and the items', await shown(page, 'online-panel', 5000)
|
||||
&& (await page.getByTestId('online-customer').textContent()).includes('Main square 3')
|
||||
&& (await page.getByTestId('online-customer').textContent()).includes('Ring twice')
|
||||
&& await page.getByTestId('online-line').count() === 1
|
||||
&& (await page.getByTestId('online-total').textContent()).includes((2 * simple.price).toFixed(2)))
|
||||
&& await page.getByTestId('online-line').count() === 1)
|
||||
const whenText = await page.getByTestId('online-when').textContent().catch(() => '')
|
||||
r.check('S.5: the delivery fee is its own line, in the total; the customer\'s time and area show',
|
||||
await page.getByTestId('online-fee').count() === 1
|
||||
&& (await page.getByTestId('online-total').textContent()).includes((2 * simple.price + FEE).toFixed(2))
|
||||
&& /\d\d:30/.test(whenText) && (await page.getByTestId('online-customer').textContent()).includes('Centre'), whenText)
|
||||
r.check('S.5: the venue\'s own fee rules differ (it has none) → the counter is warned, the customer still pays what they saw',
|
||||
await shown(page, 'online-price-diff', 3000))
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-pos-online.png') })
|
||||
const kdsHas = async () => (await api('GET', '/api/kds/orders', { token: boss })).orders.some(o => o.id === onlineId)
|
||||
r.check('3.3d: the kitchen doesn\'t see it before it is accepted', !(await kdsHas()))
|
||||
@@ -573,8 +583,11 @@ try {
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid="online-panel"]')?.dataset.status === 'delivered', null, { timeout: 8000 }).catch(() => {})
|
||||
r.check('3.3d: the driver\'s cash taken at the counter → delivered', await page.getByTestId('online-panel').getAttribute('data-status') === 'delivered')
|
||||
for (let i = 0; i < 20 && drawerBytes.length === drawerBeforeOnline; i++) await sleep(100)
|
||||
r.check('3.3d: …the drawer opened and the items are paid', drawerBytes.length > drawerBeforeOnline
|
||||
&& (await api('GET', `/api/orders/${onlineId}`, { token: boss })).items.every(i => i.status === 'paid'))
|
||||
const paidOnline = await api('GET', `/api/orders/${onlineId}`, { token: boss })
|
||||
r.check('3.3d: …the drawer opened and the items are paid (S.5: the fee too)', drawerBytes.length > drawerBeforeOnline
|
||||
&& paidOnline.items.every(i => i.status === 'paid') && paidOnline.items.some(i => i.system_key === 'delivery_fee' && i.unit_price === FEE))
|
||||
r.check('S.5: …the kitchen never got the fee line', !(await api('GET', '/api/kds/orders', { token: boss })).orders
|
||||
.some(o => o.items.some(i => paidOnline.items.find(x => x.id === i.id)?.system_key)))
|
||||
for (let i = 0; i < 30 && !cloud.statuses.some(x => x.id === 41 && x.status === 'delivered'); i++) await sleep(100)
|
||||
r.check('3.3d: …and the cloud heard every step', ['accepted', 'preparing', 'out_for_delivery', 'delivered']
|
||||
.every(st => cloud.statuses.some(x => x.id === 41 && x.status === st)), JSON.stringify(cloud.statuses))
|
||||
|
||||
Reference in New Issue
Block a user