feat(connect): the site side of online orders: fee line, customer's time, price check

Plan phase 3S, step S.5.
- Pull: an online order keeps the customer's time (orders.requested_for, None = as soon as
  possible) and delivery area; quick options are stored in the site's entry shape; items get
  their cost snapshot.
- The delivery fee is its own order line: a system product (products.system_key
  "delivery_fee", lifecycle "system", sold nowhere; services/system_products.py), created on
  first use in the venue's language with the VAT group most products use. Added printed and
  served, so kitchen tickets and the KDS never see it; paid at the counter with the items,
  counted in the shift, on the fiscal receipt with its VAT group. Never listed in the
  catalogue (products list, export, edit endpoints → 404) and never added by hand.
- Price check (services/online_check.py): each line priced as the snapshot prices it, at the
  order's time, and the fee through the same engine with the site's rules and the cloud's
  area id; differences kept on orders.online_price_diff and shown. The customer pays what
  the cloud charged.
- Counter: time chip (or as soon as possible), area, fee line, price warning; takeaway is
  its own kind (was shown as "at the venue") and finishes as "collected". KDS cards show the
  online reference and the time; kitchen tickets print the reference, the type and the time.
- Manager: Online ordering → "The fee on the receipt" (name, VAT group;
  PUT /api/connect/fees/fee-product, fees.vat_group_unknown); the online orders page shows
  the time, area and price warning.
- Migration 0019. Tests: tests/test_online_site_side.py (6), terminal unit test, e2e
  (terminal: fee, time, warning, paid in full; manager: fee line settings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 15:38:25 +02:00
co-authored by Claude Opus 5.5
parent 8ea44d71aa
commit 0ca700279a
38 changed files with 899 additions and 69 deletions
@@ -0,0 +1,51 @@
// The delivery fee on the bill and the fiscal receipt (plan phase 3S, step S.5). An online
// delivery order's fee arrives as its own line (a system product the venue never sells by
// hand), so the counter takes items + fee and the receipt prints it. Here the venue names
// that line and picks its VAT group. PUT /api/connect/fees/fee-product.
import { useState } from 'react'
import toast from 'react-hot-toast'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Field, Input, Select } from '@xenia/ui'
import client from '../../api/client'
export default function FeeProductCard({ product, onSaved }) {
const { t } = useTranslation('manager')
const [name, setName] = useState(product.name ?? '')
const [vat, setVat] = useState(product.vat_group_id == null ? '' : String(product.vat_group_id))
const [busy, setBusy] = useState(false)
const groups = product.vat_groups ?? []
const save = async () => {
setBusy(true)
try {
await client.put('/api/connect/fees/fee-product', { name: name.trim(), vat_group_id: vat === '' ? null : Number(vat) })
toast.success(t('fees.saved'))
onSaved?.()
} catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
}
return (
<section className="p-4 rounded-card border border-line bg-surface grid gap-3" aria-labelledby="fee-product-h" data-testid="fee-product">
<div className="grid gap-1">
<h2 id="fee-product-h" className="text-title font-semibold text-ink">{t('feeProduct.title')}</h2>
<p className="text-label text-ink-2">{t('feeProduct.intro')}</p>
</div>
<Field label={t('feeProduct.name')}>
<Input value={name} maxLength={40} onChange={e => setName(e.target.value)} data-testid="fee-product-name" />
</Field>
<Field label={t('feeProduct.vat')} hint={groups.length ? undefined : t('feeProduct.noGroups')}>
{groups.length ? (
<Select value={vat} onChange={e => setVat(e.target.value)} data-testid="fee-product-vat">
<option value="">{t('feeProduct.vatNone')}</option>
{groups.map(g => <option key={g.machine_id} value={String(g.machine_id)}>{g.friendly_name || g.machine_id}</option>)}
</Select>
) : (
<Input inputMode="numeric" value={vat} onChange={e => setVat(e.target.value.replace(/\D/g, ''))} data-testid="fee-product-vat" />
)}
</Field>
<div><Button onClick={save} loading={busy} disabled={!name.trim()} data-testid="fee-product-save">{t('fees.save')}</Button></div>
</section>
)
}
@@ -1,5 +1,5 @@
// Online ordering (plan phase 3S, steps S.3–S.4): the ordering settings (OrderingSettings),
// delivery areas and fees. Backend: /api/connect/fees
// Online ordering (plan phase 3S, steps S.3–S.5): the ordering settings (OrderingSettings),
// delivery areas and fees, and the fee's line on the receipt (FeeProductCard). Backend: /api/connect/fees
// (connect_orders.fees). The venue lists the areas it delivers to and the fee rules, looked
// at from the top: a rule whose conditions hold changes the fee (set, add, % of the
// products, free) or refuses the order below a minimum; "stop here" makes the first match
@@ -13,6 +13,7 @@ import { useFormat, useTranslation } from '@xenia/i18n'
import { SALES_POINTS } from '@xenia/access'
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, Spinner, Switch } from '@xenia/ui'
import client from '../../api/client'
import FeeProductCard from './FeeProductCard'
import OrderingSettings from './OrderingSettings'
import { ACTIONS, DAYS, describeRule, emptyRule, moveRule, parsePostcodes, previewBody, ruleBody, ruleProblems, ruleToForm } from './feesLogic'
@@ -109,6 +110,7 @@ export default function FeesPage() {
)}
</section>
<TestOrder areas={data.areas} />
{data.fee_product && <FeeProductCard key={JSON.stringify(data.fee_product)} product={data.fee_product} onSaved={load} />}
</div>
</div>