feat(backend,terminal): online orders on the counter POS (platform-v2 step 3.3d)
- Counter POS gets an "Online" mode (module on + connect_orders.manage): New / In
progress / Finished, a chime on arrival (and every 30 s while one waits), badge,
toast in any mode; the order panel offers only the next step: accept / reject with
a reason, preparing, ready or out for delivery, then take the payment (shared
PaymentDialog, drawer, shift) and mark delivered/served.
- connect_orders router on v2 conventions: require(connect_orders.manage), error
codes online.not_found / online.status_changed, the cloud's step order enforced,
audit rows, GET /api/connect/orders/board. POS device scope gains connect_orders.*;
barista and barman get the key by default.
- Fixes: the KDS showed online orders before acceptance; accepting printed no
kitchen tickets; a pull whose synced mark failed stored the order twice
(store_online_orders skips known cloud ids); pulled orders lacked the business day
and delivery type; rejected orders kept active items; delivered sets closed_at/by.
- Online orders belong to holders of connect_orders.manage (_can_access_order), so
the counter pays them with POST /api/pos/orders/{id}/pay.
- Tests: test_pos_online.py (5), terminal unit +1, terminal.mjs +17 with a fake
cloud (pull, synced, status mirror); fixed a timing race in a 3.3c check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// Online orders at the counter (plan step 3.3d): what the list shows and which step comes next.
|
||||
// The orders come from GET /api/connect/orders/board; the steps follow the backend's (and the
|
||||
// cloud's) order: accept or reject → preparing → ready (at the venue) or out for delivery →
|
||||
// delivered. Pure: unit-tested in Node (tests/pos.test.mjs).
|
||||
|
||||
export const ONLINE_LISTS = ['incoming', 'in_progress', 'finished']
|
||||
|
||||
/** The next step of an order: { kind: 'answer' } (accept / reject), { kind: 'status', to },
|
||||
* { kind: 'finish', pay } (take what's unpaid, then delivered) or null (finished). */
|
||||
export function nextStep(order) {
|
||||
switch (order.status) {
|
||||
case 'pending_acceptance': return { kind: 'answer' }
|
||||
case 'accepted': return { kind: 'status', to: 'preparing' }
|
||||
case 'preparing': return { kind: 'status', to: order.type === 'delivery' ? 'out_for_delivery' : 'ready' }
|
||||
case 'ready':
|
||||
case 'out_for_delivery': return { kind: 'finish', pay: order.unpaid > 0.004 }
|
||||
default: return null
|
||||
}
|
||||
}
|
||||
|
||||
/** The order with this id in any of the board's lists (null when gone). */
|
||||
export function findOnline(board, id) {
|
||||
if (!board || id == null) return null
|
||||
for (const list of ONLINE_LISTS) {
|
||||
const hit = (board[list] ?? []).find(o => o.id === id)
|
||||
if (hit) return hit
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** Whole minutes since an ISO time (never negative). */
|
||||
export function minutesSince(iso, now = Date.now()) {
|
||||
return Math.max(0, Math.floor((now - Date.parse(iso)) / 60_000))
|
||||
}
|
||||
Reference in New Issue
Block a user