feat(ordering): orders priced by the server (platform-v2 step 4.4)
The waiter app (and the manager's ordering tab) send what was chosen, by id; the
server prices it with the counter's code. No app sends a price any more.
- POST /api/orders/{id}/items takes `lines` (pos_cart's line + course_id,
price_adjustment, is_service_item): sales point checked first, refusals name the
product and line (order.line.*, order.not_sold_here); prices or selected_options in a
line -> order.line.client_price, the old `items` shape -> order.lines_required; a
by-hand price change needs ordering.prices.modify or a manager's approval (audited
PRICE_SET_BY_HAND). add_priced_items is the one writer of priced items (pos too).
- POST /api/orders/quote: the cart's total before sending; /api/pos/quote shares
pos_cart.quote().
- pos_cart: a preference set left out takes its default; a set at its free default
isn't stored; a default that costs is charged (the waiter never sent it: fixed);
an extra's sub-choice is charged per extra (the counter charged it once: fixed).
- @xenia/api lines.js: lineFromOptions / wireLine / estimate / LineError.
- Waiter: lines on send; cart total from the quote ("≈ estimate" offline); summary
shows the same prices; offline orders queued by id, priced on sync, refused lines
shown on a "Δεν στάλθηκαν" sheet (no empty order opened); dead ItemOptionsModal gone.
- Tests: test_order_lines.py (14), lines.test.mjs, waiter e2e +6.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { useState, useRef, useCallback, useEffect } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../api/client'
|
||||
import { LineError, wireLine } from '@xenia/api'
|
||||
import ManagerOrderDrawer from './ManagerOrderDrawer'
|
||||
|
||||
// ── Constants ─────────────────────────────────────────────────────────────────
|
||||
@@ -494,8 +495,9 @@ export default function DesktopOrderingTab({ orderId, tableId, orderStatus }) {
|
||||
const { data: newOrder } = await client.post('/api/orders/', { table_id: tableId })
|
||||
activeOrderId = newOrder.id
|
||||
}
|
||||
// what was chosen, by id: the server prices it (plan step 4.4)
|
||||
const res = await client.post(`/api/orders/${activeOrderId}/items`, {
|
||||
items: cart.map(({ _key, _drawerState, ...item }) => item),
|
||||
lines: cart.map(({ _key, _drawerState, ...item }) => wireLine(item, products.find(p => p.id === item.product_id))),
|
||||
order_note: orderNote || null,
|
||||
})
|
||||
return res.data
|
||||
@@ -514,7 +516,9 @@ export default function DesktopOrderingTab({ orderId, tableId, orderStatus }) {
|
||||
qc.invalidateQueries({ queryKey: ['orders-active'] })
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err?.response?.data?.detail || 'Σφάλμα αποστολής παραγγελίας')
|
||||
toast.error(err instanceof LineError
|
||||
? `«${err.product}»: το «${err.what}» δεν υπάρχει πια στο μενού`
|
||||
: err?.response?.data?.detail || 'Σφάλμα αποστολής παραγγελίας')
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user