feat(manager): the venue's online ordering link and QR code on the Online ordering page
Plan phase 3S, step S.99.
- GET /api/connect/fees returns `links` {order, menu}: the ordering app and QR menu
addresses, from the cloud's apps_url (heartbeat) and the site id.
- Manager: "Your ordering link" card (OrderingLink.jsx) on Online ordering: the address, its
QR code, copy / open / print, to share or put on the website and window.
- Pack README: routers/fees.py row.
- Tests: the link (backend), the card (manager e2e).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -45,6 +45,7 @@ The manager calls the API **same-origin, with relative paths**. The waiter app r
|
|||||||
| `local_backend/services/system_products.py`, `services/online_check.py` | Lines the system adds itself (phase 3S): the delivery fee is an order line whose product has `system_key` and `lifecycle_status = "system"` (never on a menu or in the catalogue, never added by hand, added printed + served so the kitchen never sees it; paid, counted, receipted and refunded like any line). The site's own price check of a pulled online order (`orders.online_price_diff`): shown, never applied — the customer pays the cloud's prices |
|
| `local_backend/services/system_products.py`, `services/online_check.py` | Lines the system adds itself (phase 3S): the delivery fee is an order line whose product has `system_key` and `lifecycle_status = "system"` (never on a menu or in the catalogue, never added by hand, added printed + served so the kitchen never sees it; paid, counted, receipted and refunded like any line). The site's own price check of a pulled online order (`orders.online_price_diff`): shown, never applied — the customer pays the cloud's prices |
|
||||||
| `local_backend/services/online_reservations.py` | Table bookings from the online ordering app (phase 3S): stored as `Reservation` rows (`requested` → `pending` confirmed / `declined`; `arrived`, `cancelled`, `no_show`), food ordered ahead kept on the booking (`items_json`) and turned into an order **only at the fire time** (`fire_worker`, a connect_orders module worker; needs an open business day) or on early arrival. Every step mirrors the cloud status. The counter's Online → Bookings and `/api/connect/bookings/*` use it; the reservations router delegates online bookings to it |
|
| `local_backend/services/online_reservations.py` | Table bookings from the online ordering app (phase 3S): stored as `Reservation` rows (`requested` → `pending` confirmed / `declined`; `arrived`, `cancelled`, `no_show`), food ordered ahead kept on the booking (`items_json`) and turned into an order **only at the fire time** (`fire_worker`, a connect_orders module worker; needs an open business day) or on early arrival. Every step mirrors the cloud status. The counter's Online → Bookings and `/api/connect/bookings/*` use it; the reservations router delegates online bookings to it |
|
||||||
| `local_backend/services/table_qr.py`, `services/qr_orders.py` | The QR menu at the table (phase 3S): every active table has a random `qr_token`; the menu snapshot carries only its sha256 (`qr`), so the cloud can check a code but never make one. A new code (rotate) kills the printed one at the next push (`/api/tables` and `/api/connect/qr` are in `MENU_PATHS`). A QR order with a valid table goes straight onto the table's open order (or a new one), to the kitchen, with a `qr_order` message to the table's waiters; the audit row `QR_ORDER` (note = the cloud ref) keeps repeats out. Manager page `/online/qr` |
|
| `local_backend/services/table_qr.py`, `services/qr_orders.py` | The QR menu at the table (phase 3S): every active table has a random `qr_token`; the menu snapshot carries only its sha256 (`qr`), so the cloud can check a code but never make one. A new code (rotate) kills the printed one at the next push (`/api/tables` and `/api/connect/qr` are in `MENU_PATHS`). A QR order with a valid table goes straight onto the table's open order (or a new one), to the kitchen, with a `qr_order` message to the table's waiters; the audit row `QR_ORDER` (note = the cloud ref) keeps repeats out. Manager page `/online/qr` |
|
||||||
|
| `local_backend/routers/fees.py` | The venue's online ordering settings (`connect_orders.ordering`: services, hours, slots, ASAP; `reservations`: bookings, food ahead, fire minutes), delivery areas and fee rules, the fee line's name/VAT, and the venue's links (`links.order`, `links.menu` from the cloud's `apps_url`). Everything here travels to the cloud in the menu snapshot (contract C-2) |
|
||||||
| `local_backend/routers/ws.py` | Real-time event stream (seq + cursor replay) |
|
| `local_backend/routers/ws.py` | Real-time event stream (seq + cursor replay) |
|
||||||
| `waiter_pwa/src/config/server.js` | **Where the backend is**: active venue, `apiBase()`, `wsUrl()`, `assetUrl()`, `storageKey()`, `dbName()`, `deliveryMode()` |
|
| `waiter_pwa/src/config/server.js` | **Where the backend is**: active venue, `apiBase()`, `wsUrl()`, `assetUrl()`, `storageKey()`, `dbName()`, `deliveryMode()` |
|
||||||
| `waiter_pwa/android/`, `capacitor.config.json` | Native Android app (Capacitor 8). See "Native Android app" below |
|
| `waiter_pwa/android/`, `capacitor.config.json` | Native Android app (Capacitor 8). See "Native Android app" below |
|
||||||
|
|||||||
@@ -247,8 +247,12 @@ def list_fees(db: Session = Depends(get_db), user=Depends(require(KEY))):
|
|||||||
from services import system_products
|
from services import system_products
|
||||||
fee_product = system_products.get(db, system_products.DELIVERY_FEE)
|
fee_product = system_products.get(db, system_products.DELIVERY_FEE)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
from config import settings
|
||||||
|
from services.table_qr import apps_url, menu_url
|
||||||
return {**fees_payload(db), "ordering": ordering_settings(db),
|
return {**fees_payload(db), "ordering": ordering_settings(db),
|
||||||
"fee_product": {**system_products.out(fee_product), "vat_groups": _vat_groups(db)}}
|
"fee_product": {**system_products.out(fee_product), "vat_groups": _vat_groups(db)},
|
||||||
|
# the venue's ordering link (S.99): to share, print or put on the website
|
||||||
|
"links": {"order": f"{apps_url()}/order/{settings.SITE_ID or ''}", "menu": menu_url()}}
|
||||||
|
|
||||||
|
|
||||||
def _vat_groups(db) -> list[dict]:
|
def _vat_groups(db) -> list[dict]:
|
||||||
|
|||||||
@@ -168,3 +168,11 @@ def test_kitchen_ticket_shows_the_reference_and_the_time(db, menu):
|
|||||||
assert _place(order, "None") == "ORD-0605"
|
assert _place(order, "None") == "ORD-0605"
|
||||||
order.requested_for = None
|
order.requested_for = None
|
||||||
assert _online_meta(order)[1] == ("For:", "As soon as possible")
|
assert _online_meta(order)[1] == ("For:", "As soon as possible")
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_venues_ordering_link(client, owner_h, monkeypatch):
|
||||||
|
from services import cloud_sync
|
||||||
|
monkeypatch.setitem(cloud_sync.license_state, "apps_url", "https://menu.example.com")
|
||||||
|
monkeypatch.setattr(cloud_sync.settings, "SITE_ID", "taverna-1")
|
||||||
|
links = client.get("/api/connect/fees", headers=owner_h).json()["links"]
|
||||||
|
assert links == {"order": "https://menu.example.com/order/taverna-1", "menu": "https://menu.example.com/menu/taverna-1"}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { SALES_POINTS } from '@xenia/access'
|
|||||||
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, Spinner, Switch } from '@xenia/ui'
|
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, Spinner, Switch } from '@xenia/ui'
|
||||||
import client from '../../api/client'
|
import client from '../../api/client'
|
||||||
import FeeProductCard from './FeeProductCard'
|
import FeeProductCard from './FeeProductCard'
|
||||||
|
import OrderingLink from './OrderingLink'
|
||||||
import OrderingSettings from './OrderingSettings'
|
import OrderingSettings from './OrderingSettings'
|
||||||
import { ACTIONS, DAYS, describeRule, emptyRule, moveRule, parsePostcodes, previewBody, ruleBody, ruleProblems, ruleToForm } from './feesLogic'
|
import { ACTIONS, DAYS, describeRule, emptyRule, moveRule, parsePostcodes, previewBody, ruleBody, ruleProblems, ruleToForm } from './feesLogic'
|
||||||
|
|
||||||
@@ -57,6 +58,8 @@ export default function FeesPage() {
|
|||||||
<h1 className="text-heading font-semibold text-ink">{t('ordering.pageTitle')}</h1>
|
<h1 className="text-heading font-semibold text-ink">{t('ordering.pageTitle')}</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
{data.links?.order && <OrderingLink url={data.links.order} />}
|
||||||
|
|
||||||
<OrderingSettings key={JSON.stringify(data.ordering)} ordering={data.ordering} />
|
<OrderingSettings key={JSON.stringify(data.ordering)} ordering={data.ordering} />
|
||||||
|
|
||||||
<div className="grid gap-1">
|
<div className="grid gap-1">
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// The venue's online ordering link (plan phase 3S, wrap-up): the address of its ordering app
|
||||||
|
// (takeaway, delivery, table bookings) to share, put on the website or social pages, or print
|
||||||
|
// as a QR code for flyers and the shop window. GET /api/connect/fees → links.order (the cloud
|
||||||
|
// tells the venue where the customer apps live: PUBLIC_APPS_URL, sent with the heartbeat).
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { QRCodeSVG } from 'qrcode.react'
|
||||||
|
import { Copy, ExternalLink, Printer } from 'lucide-react'
|
||||||
|
import { useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button } from '@xenia/ui'
|
||||||
|
|
||||||
|
export default function OrderingLink({ url }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const copy = async () => {
|
||||||
|
try { await navigator.clipboard.writeText(url); toast.success(t('orderingLink.copied')) } catch { toast.error(url) }
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<section className="p-4 rounded-card border border-line bg-surface flex flex-wrap items-center gap-4 print:border-0" aria-labelledby="ordering-link-h" data-testid="ordering-link">
|
||||||
|
<div className="bg-surface p-2 rounded-control border border-line"><QRCodeSVG value={url} size={112} includeMargin={false} /></div>
|
||||||
|
<div className="grid gap-2 flex-1 min-w-[16rem]">
|
||||||
|
<h2 id="ordering-link-h" className="text-title font-semibold text-ink">{t('orderingLink.title')}</h2>
|
||||||
|
<p className="text-label text-ink-2">{t('orderingLink.intro')}</p>
|
||||||
|
<a href={url} target="_blank" rel="noreferrer" className="text-body font-medium text-accent-ink break-all" data-testid="ordering-link-url">{url}</a>
|
||||||
|
<div className="flex flex-wrap gap-2 print:hidden">
|
||||||
|
<Button size="sm" variant="secondary" icon={<Copy size={14} />} onClick={copy}>{t('orderingLink.copy')}</Button>
|
||||||
|
<Button size="sm" variant="secondary" icon={<ExternalLink size={14} />} onClick={() => window.open(url, '_blank', 'noopener')}>{t('orderingLink.open')}</Button>
|
||||||
|
<Button size="sm" variant="secondary" icon={<Printer size={14} />} onClick={() => window.print()}>{t('orderingLink.print')}</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -591,5 +591,13 @@
|
|||||||
"table": "Τραπέζι {{name}}",
|
"table": "Τραπέζι {{name}}",
|
||||||
"scanOrder": "Σκανάρετε για μενού και παραγγελία",
|
"scanOrder": "Σκανάρετε για μενού και παραγγελία",
|
||||||
"scanRead": "Σκανάρετε για το μενού"
|
"scanRead": "Σκανάρετε για το μενού"
|
||||||
|
},
|
||||||
|
"orderingLink": {
|
||||||
|
"title": "Ο σύνδεσμος παραγγελιών σας",
|
||||||
|
"intro": "Εδώ οι πελάτες παραγγέλνουν για παραλαβή και διανομή και κλείνουν τραπέζι. Μοιραστείτε τον, βάλτε τον στην ιστοσελίδα σας ή τυπώστε τον QR για φυλλάδια και τη βιτρίνα.",
|
||||||
|
"copy": "Αντιγραφή",
|
||||||
|
"copied": "Ο σύνδεσμος αντιγράφηκε",
|
||||||
|
"open": "Άνοιγμα",
|
||||||
|
"print": "Εκτύπωση"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -591,5 +591,13 @@
|
|||||||
"table": "Table {{name}}",
|
"table": "Table {{name}}",
|
||||||
"scanOrder": "Scan to see the menu and order",
|
"scanOrder": "Scan to see the menu and order",
|
||||||
"scanRead": "Scan to see the menu"
|
"scanRead": "Scan to see the menu"
|
||||||
|
},
|
||||||
|
"orderingLink": {
|
||||||
|
"title": "Your ordering link",
|
||||||
|
"intro": "Customers order takeaway and delivery and book tables here. Share it, put it on your website, or print its QR code for flyers and the window.",
|
||||||
|
"copy": "Copy link",
|
||||||
|
"copied": "Link copied",
|
||||||
|
"open": "Open",
|
||||||
|
"print": "Print"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -517,6 +517,8 @@ try {
|
|||||||
await page.goto(`${APP}/online/fees`)
|
await page.goto(`${APP}/online/fees`)
|
||||||
r.check('fees: the page opens from the nav entry, no rules yet', await page.getByTestId('fees-page').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
r.check('fees: the page opens from the nav entry, no rules yet', await page.getByTestId('fees-page').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||||||
&& await page.locator('a[href="/online/fees"]').count() >= 1 && await page.getByTestId('rule').count() === 0)
|
&& await page.locator('a[href="/online/fees"]').count() >= 1 && await page.getByTestId('rule').count() === 0)
|
||||||
|
r.check('ordering link: the venue\'s ordering app address is shown, with its QR code', await page.getByTestId('ordering-link').count() === 1
|
||||||
|
&& (await page.getByTestId('ordering-link-url').textContent()).endsWith('/order/test-site-1') && await page.getByTestId('ordering-link').locator('svg').count() >= 1)
|
||||||
await page.getByTestId('area-add').click()
|
await page.getByTestId('area-add').click()
|
||||||
await page.getByTestId('area-name').fill('Centre')
|
await page.getByTestId('area-name').fill('Centre')
|
||||||
await page.getByTestId('area-postcodes').fill('24100, 241 31')
|
await page.getByTestId('area-postcodes').fill('24100, 241 31')
|
||||||
|
|||||||
Reference in New Issue
Block a user