feat(backend,terminal): tables at the counter, shared live with the waiter phones (platform-v2 3.3c)
- POS: GET /api/pos/tables (the cashier's zones as in the waiter app, each open order's
totals, people, ready items, flags, reservation), POST /api/pos/tables/{id}/items (into
the table's order or a new one via orders.open_order + add_items), POST
/api/pos/orders/{id}/pay (chosen items, cash/card/split, drawer on cash), POST
/api/pos/orders/{id}/close (only when nothing is unpaid). Quote takes order_id so the
order's items count for cart conditions (shared pos_cart.order_cart, used by add_items).
- New codes pos.table_not_found, pos.table_not_yours, pos.items_changed, pos.order_unpaid.
- Fix: item cancels (DELETE item, cancel-items) now broadcast order_updated, so phones and
kitchen screens see them at once.
- Terminal: Sale | Tables switch, zone list, table cards by zone, TablePanel (order lines,
new lines, send, pay selected/all, cancel with approval, close), generic PaymentDialog.
- Tests: test_pos_tables.py (8), terminal unit, terminal.mjs +17 with a live phone socket.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -407,6 +407,94 @@ try {
|
||||
&& (await page.getByTestId('sale-done').textContent()).includes('Card') && !(await page.getByTestId('sale-done').textContent()).includes('Drawer'))
|
||||
await sleep(300)
|
||||
r.check('3.3b: …and the drawer stayed shut', drawerBytes.length === drawerBefore)
|
||||
|
||||
// ── 3.3c: tables at the counter, with a waiter's phone on the same table ─
|
||||
// the phone: Maria's live connection (as the waiter app opens it) and her API calls
|
||||
const phoneEvents = []
|
||||
const phoneWs = new WebSocket(`${backend.url.replace(/^http/, 'ws')}/api/ws/connect`)
|
||||
await new Promise(res => {
|
||||
phoneWs.onopen = () => phoneWs.send(JSON.stringify({ cursor: 0, token: maria }))
|
||||
phoneWs.onmessage = e => { const m = JSON.parse(e.data); if (m.type === 'ready') res(); else phoneEvents.push(m) }
|
||||
setTimeout(res, 5000)
|
||||
})
|
||||
const heard = async (pred, ms = 5000) => {
|
||||
for (let i = 0; i < ms / 100; i++) { if (phoneEvents.some(pred)) return true; await sleep(100) }
|
||||
return false
|
||||
}
|
||||
const mariaTables = new Set((await api('GET', '/api/tables/', { token: maria })).map(t => t.id))
|
||||
await page.getByTestId('mode-tables').click()
|
||||
r.check('3.3c: Tables shows the table list', await shown(page, 'pos-tables', 10_000))
|
||||
const counterTables = await page.evaluate(async () => (await window.__xeniaClient.get('/api/pos/tables')).data.tables)
|
||||
const shared = counterTables.find(t => !t.order && mariaTables.has(t.id))
|
||||
const tableCard = page.locator(`[data-testid="pos-table"][data-table="${shared.id}"]`)
|
||||
r.check('3.3c: …each table with its state (a free one)', await tableCard.getAttribute('data-state') === 'free')
|
||||
await tableCard.click()
|
||||
r.check('3.3c: a table opens with the product grid and its (empty) order', await shown(page, 'table-panel', 5000) && await simpleCard.isVisible())
|
||||
await simpleCard.locator('button').first().click()
|
||||
await page.getByTestId('table-send').waitFor({ timeout: 5000 })
|
||||
await page.waitForFunction(() => !document.querySelector('[data-testid="table-send"]')?.disabled, null, { timeout: 5000 }).catch(() => {})
|
||||
await page.getByTestId('table-send').click()
|
||||
await page.waitForFunction(() => document.querySelectorAll('[data-testid="order-line"]').length === 1, null, { timeout: 8000 }).catch(() => {})
|
||||
const tableOrder = Number(await page.getByTestId('table-panel').getAttribute('data-order'))
|
||||
r.check('3.3c: Send opens the table\'s order with the line', tableOrder > 0 && await page.getByTestId('order-line').count() === 1)
|
||||
r.check('3.3c: the phone hears it at once (live)', await heard(m => m.type === 'order_updated' && m.data.order_id === tableOrder && m.data.action === 'items_added'))
|
||||
const onPhone = await api('GET', `/api/orders/${tableOrder}`, { token: maria })
|
||||
r.check('3.3c: …and sees the counter\'s order on that table', onPhone.table_id === shared.id && onPhone.items.length === 1)
|
||||
|
||||
// the phone adds two items → the counter shows them without a reload
|
||||
await api('POST', `/api/orders/${tableOrder}/items`, { token: maria, body: { items: [
|
||||
{ product_id: simple.id, quantity: 1, notes: 'from the phone' }, { product_id: simple.id, quantity: 1, notes: 'to cancel' }] } })
|
||||
await page.waitForFunction(() => document.querySelectorAll('[data-testid="order-line"]').length === 3, null, { timeout: 8000 }).catch(() => {})
|
||||
r.check('3.3c: the phone adds items → the counter shows them live', await page.getByTestId('order-line').count() === 3
|
||||
&& (await page.getByTestId('order-lines').textContent()).includes('from the phone'))
|
||||
|
||||
// cancel one from the counter (the cashier is a manager here: no approval needed)
|
||||
const afterPhone = await api('GET', `/api/orders/${tableOrder}`, { token: maria })
|
||||
const toCancel = afterPhone.items.find(i => i.notes === 'to cancel').id
|
||||
const fromPhone = afterPhone.items.find(i => i.notes === 'from the phone').id
|
||||
await page.locator(`[data-testid="order-line"][data-item="${toCancel}"]`).click()
|
||||
await page.getByTestId('table-cancel').click()
|
||||
await page.getByTestId('cancel-confirm').click()
|
||||
await page.waitForFunction(() => document.querySelectorAll('[data-testid="order-line"]').length === 2, null, { timeout: 8000 }).catch(() => {})
|
||||
r.check('3.3c: cancel at the counter takes the item off', await page.getByTestId('order-line').count() === 2)
|
||||
r.check('3.3c: …and the phone hears it', await heard(m => m.type === 'order_updated' && m.data.action === 'items_cancelled' && m.data.item_ids?.includes(toCancel)))
|
||||
|
||||
// pay the phone's item in cash (selected), then the rest by card, then close
|
||||
await page.locator(`[data-testid="order-line"][data-item="${fromPhone}"]`).click()
|
||||
await page.getByTestId('table-pay').click()
|
||||
await page.getByTestId('payment-dialog').waitFor({ timeout: 5000 })
|
||||
r.check('3.3c: Pay takes only the selected item', (await page.getByTestId('pay-confirm').textContent()).includes(simple.price.toFixed(2)))
|
||||
const drawerBeforeTable = drawerBytes.length
|
||||
await page.getByTestId('pay-confirm').click()
|
||||
const paidShown = await shown(page, 'table-paid', 8000)
|
||||
// the order reloads after the payment (live, coalesced): wait for the line to turn paid
|
||||
await page.waitForFunction(() => document.querySelectorAll('[data-testid="order-line"][data-paid="true"]').length === 1, null, { timeout: 8000 }).catch(() => {})
|
||||
r.check('3.3c: paid some items: the panel says so and the item shows as paid', paidShown
|
||||
&& await page.locator('[data-testid="order-line"][data-paid="true"]').count() === 1)
|
||||
for (let i = 0; i < 20 && drawerBytes.length === drawerBeforeTable; i++) await sleep(100)
|
||||
r.check('3.3c: …cash opens the drawer here too', drawerBytes.length > drawerBeforeTable)
|
||||
r.check('3.3c: the phone sees the payment', await heard(m => m.type === 'order_paid' && m.data.order_id === tableOrder)
|
||||
&& (await api('GET', `/api/orders/${tableOrder}`, { token: maria })).items.find(i => i.id === fromPhone).status === 'paid')
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-pos-table.png') })
|
||||
await page.getByTestId('table-pay').click()
|
||||
await page.getByTestId('pay-card').click()
|
||||
await page.getByTestId('pay-confirm').click()
|
||||
r.check('3.3c: everything paid → Close', await shown(page, 'table-close', 8000))
|
||||
await page.getByTestId('table-close').click()
|
||||
r.check('3.3c: closed → back to the list, the table is free again', await shown(page, 'pos-tables', 8000)
|
||||
&& await page.waitForFunction(id => document.querySelector(`[data-testid="pos-table"][data-table="${id}"]`)?.dataset.state === 'free', shared.id, { timeout: 5000 }).then(() => true).catch(() => false))
|
||||
r.check('3.3c: the phone hears the table close', await heard(m => m.type === 'order_closed' && m.data.order_id === tableOrder))
|
||||
|
||||
// a waiter opens a table on the phone → the counter's list shows it live
|
||||
const phoneTable = counterTables.find(t => !t.order && mariaTables.has(t.id) && t.id !== shared.id)
|
||||
const phoneOrder = await api('POST', '/api/orders/', { token: maria, body: { table_id: phoneTable.id } })
|
||||
await api('POST', `/api/orders/${phoneOrder.id}/items`, { token: maria, body: { items: [{ product_id: simple.id, quantity: 2 }] } })
|
||||
r.check('3.3c: a table opened on the phone shows on the counter at once, with what\'s due',
|
||||
await page.waitForFunction(id => document.querySelector(`[data-testid="pos-table"][data-table="${id}"]`)?.dataset.state === 'open', phoneTable.id, { timeout: 8000 }).then(() => true).catch(() => false)
|
||||
&& (await page.locator(`[data-testid="pos-table"][data-table="${phoneTable.id}"]`).textContent()).includes((2 * simple.price).toFixed(2)))
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-pos-tables.png') })
|
||||
phoneWs.close()
|
||||
await page.getByTestId('mode-sale').click()
|
||||
drawerServer.close()
|
||||
await page.getByRole('button', { name: 'Sign out' }).click()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user