feat(backend): KDS item claims across screens; zone screens only touch their own items (platform-v2 3.2c)
- order_items.claimed_by / claimed_at (Alembic 0015). POST/DELETE
/api/kds/orders/{id}/items/{item}/claim (kds.bump): someone else's claim is refused
(kds.item_claimed), letting go works for anyone with kds.bump; live kds_item_claimed.
In progress claims for whoever did it; done/served/pending/declined clear the claim.
- Fix: order-level status and decline from a zone screen changed every zone's items;
now only the screen's zone, and a zone screen sees the order status of its own items.
- Terminal: "I'm on it" / "Let go" on the selected card, the cook's name on claimed items.
- Tests: backend +6, terminal unit +1, terminal.mjs +6 with a second screen and cook.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -222,6 +222,44 @@ try {
|
||||
await page.waitForFunction(id => document.querySelector(`[data-testid="kds-card"][data-order="${id}"]`)?.dataset.status === 'pending', second.id, { timeout: 5000 }).catch(() => {})
|
||||
r.check('3.2b: a change made elsewhere shows on the screen by itself', await card2.getAttribute('data-status') === 'pending')
|
||||
|
||||
// ── 3.2c: two screens on the same zone, two cooks, claims ────────────────
|
||||
const chef2 = await api('POST', '/api/waiters/', { token: boss, body: { username: 'term_chef2', full_name: 'Nikos Cook', nickname: 'Nikos', pin: '5858', role: 'chef', is_active: true } })
|
||||
const page2 = await screen(await (await browser.newContext({ viewport: { width: 1280, height: 800 } })).newPage())
|
||||
await pairFromManager(page2, boss, { app_key: 'kds', name: 'Kitchen 2', login_mode: 'pin', config: { prep_zone_id: grill.id } })
|
||||
await page2.locator(`[data-user="${chef2.id}"]`).click({ timeout: 15_000 })
|
||||
await page2.keyboard.type('5858')
|
||||
await page2.keyboard.press('Enter')
|
||||
await page2.getByTestId('kds-start').click({ timeout: 15_000 })
|
||||
const other = page2.locator(`[data-testid="kds-card"][data-order="${second.id}"]`)
|
||||
await other.waitFor({ timeout: 8000 })
|
||||
const pill = (loc, name) => loc.locator('[data-testid="item-claim"]', { hasText: name }).waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
|
||||
const noPill = loc => loc.locator('[data-testid="item-claim"]').waitFor({ state: 'detached', timeout: 5000 }).then(() => true).catch(() => false)
|
||||
|
||||
await card2.click({ position: { x: 20, y: 120 } })
|
||||
await card2.getByTestId('card-claim').click()
|
||||
r.check('3.2c: Maria says "I\'m on it" → the other screen shows her name on the item, live', await pill(other, 'Maria'))
|
||||
await other.click({ position: { x: 20, y: 120 } })
|
||||
r.check('3.2c: on the other screen there is nothing left to take (no claim button)',
|
||||
await other.getByTestId('card-prepare').isVisible() && await other.getByTestId('card-claim').count() === 0)
|
||||
const takeover = await page2.evaluate(async ([o, i]) => {
|
||||
try { await window.__xeniaClient.post(`/api/kds/orders/${o}/items/${i}/claim`); return 'allowed' } catch (e) { return e.response?.data?.error?.code }
|
||||
}, [second.id, item2Id])
|
||||
r.check('3.2c: Nikos can\'t take Maria\'s item (kds.item_claimed)', takeover === 'kds.item_claimed', takeover)
|
||||
await page2.keyboard.press('Escape')
|
||||
|
||||
await card2.click({ position: { x: 20, y: 120 } })
|
||||
await card2.getByTestId('card-claim').click() // Maria lets go
|
||||
r.check('3.2c: Maria lets go → the name goes on the other screen', await noPill(other))
|
||||
await other.click({ position: { x: 20, y: 120 } })
|
||||
await other.getByTestId('card-claim').click() // Nikos takes it
|
||||
r.check('3.2c: Nikos takes it → Maria\'s screen shows "Nikos"', await pill(card2, 'Nikos'))
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-kds-claim.png') })
|
||||
await other.click({ position: { x: 20, y: 120 } })
|
||||
await other.locator('[data-item]').first().click() // Nikos bumps it: done
|
||||
r.check('3.2c: bumping clears the claim (both screens, backend)', await noPill(card2) && (await kdsItem(second.id, item2Id))?.claimed_by == null
|
||||
&& (await kdsItem(second.id, item2Id))?.kds_status === 'done')
|
||||
await page2.context().close()
|
||||
|
||||
await page.getByRole('button', { name: 'Sign out' }).click()
|
||||
r.check('sign out → back to the names', await shown(page, 'user-grid'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user