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:
2026-11-17 03:35:03 +02:00
co-authored by Claude Opus 5.5
parent bcf91bf6e9
commit 8e0a786bbc
25 changed files with 1052 additions and 656 deletions
+4 -4
View File
@@ -120,7 +120,7 @@ try {
const [p1, p2] = (await api('GET', '/api/products/', { token: boss })).filter(p => p.is_active !== false)
await api('POST', '/api/products/bulk-prep-zones', { token: boss, body: { product_ids: [p1.id], prep_zone_ids: [grill.id] } })
await api('POST', '/api/products/bulk-prep-zones', { token: boss, body: { product_ids: [p2.id], prep_zone_ids: [bar.id] } })
await api('POST', `/api/orders/${opened.id}/items`, { token: maria, body: { items: [p1, p2].map(p => ({ product_id: p.id, quantity: 1 })) } })
await api('POST', `/api/orders/${opened.id}/items`, { token: maria, body: { lines: [p1, p2].map(p => ({ product_id: p.id, quantity: 1 })) } })
await api('PATCH', `/api/devices/${kitchen.id}`, { token: boss, body: { config: { prep_zone_id: grill.id, font_scale: 120 } } })
const order = (await api('GET', '/api/kds/orders', { token: boss })).orders.find(o => o.id === opened.id)
const calls = [
@@ -184,7 +184,7 @@ try {
const chimes0 = await page.evaluate(() => window.__xeniaChimes || 0)
const table2 = (await api('GET', '/api/tables/', { token: boss })).find(t => !t.open_order_id && !t.current_order_id && t.id !== table.id)
const second = await api('POST', '/api/orders/', { token: maria, body: { table_id: table2.id } })
await api('POST', `/api/orders/${second.id}/items`, { token: maria, body: { items: [{ product_id: p1.id, quantity: 2 }] } })
await api('POST', `/api/orders/${second.id}/items`, { token: maria, body: { lines: [{ product_id: p1.id, quantity: 2 }] } })
const card2 = page.locator(`[data-testid="kds-card"][data-order="${second.id}"]`)
r.check('3.2b: a new order appears by itself (live) and chimes', await card2.waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
&& await page.evaluate(() => window.__xeniaChimes || 0) > chimes0)
@@ -464,7 +464,7 @@ try {
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: [
await api('POST', `/api/orders/${tableOrder}/items`, { token: maria, body: { lines: [
{ 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
@@ -510,7 +510,7 @@ try {
// 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 }] } })
await api('POST', `/api/orders/${phoneOrder.id}/items`, { token: maria, body: { lines: [{ 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',
// (opened, then its items: wait for both, the card shows the order before its items arrive)
await page.waitForFunction(([id, due]) => {