feat(cloud): the QR menu at the table, ordering only with a table's QR code

Plan phase 3S, step S.7.
- services/qr.py: the snapshot's `qr` {ordering, tables: [{id, label, token_hash}]} (sha256
  of each table's token; the cloud never holds the tokens). A table order (dine_in) needs
  the venue's ordering on, the site's menu_mode "order" and a valid table token: otherwise
  order.service_unavailable / 403 order.table_invalid (a forged, old or typed-in table is
  refused). The order keeps the table's id and label (online_orders.table_id, migration 0006).
- Public menu: ?t=<token> → `table` {id, label} or `table_invalid`; `table_ordering`; `qr`
  never leaves the cloud.
- Heartbeat returns `apps_url` (new setting PUBLIC_APPS_URL: where /menu/ and /order/ are
  served) so sites can print table QR codes that open the right address.
- Menu app: the table from its QR code (kept for the visit), a "Table 5" banner, ordering
  only at a real table (otherwise read-only, with a notice for an invalid code); checkout
  without a typed table number; prices are the QR menu's (sales point qr_table — it showed
  in-store prices since S.1 removed digital_price) and only products sold there; the
  confirmation page for table orders (in the kitchen); the delivery/takeaway leftovers
  removed (they have their own app since S.4); test ids for e2e.
- Tests: tests/test_qr.py (3); test_checkout's typed-table case moved there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 01:26:33 +02:00
co-authored by Claude Opus 5.5
parent 3459c80611
commit 2835b5dc68
17 changed files with 245 additions and 74 deletions
+1
View File
@@ -40,4 +40,5 @@ def heartbeat(
waiter_domain=site.waiter_domain,
site_numeric_id=site.id,
license_token=issue_license_token(site, now),
apps_url=settings.PUBLIC_APPS_URL.rstrip("/") or None,
)
+10 -2
View File
@@ -30,8 +30,9 @@ def _require_site(
# ── Public ────────────────────────────────────────────────────────────────────
@router.get("/{site_slug}")
def get_menu(site_slug: str, db: Session = Depends(get_db)):
"""Return the latest menu snapshot for a site. Used by the public menu SPA."""
def get_menu(site_slug: str, t: str | None = None, db: Session = Depends(get_db)):
"""Return the latest menu snapshot for a site. Used by the public menu SPA. `t`: a table's
QR token (S.7) → `table` {id, label}, or `table_invalid` when it isn't one of the venue's."""
site = db.query(Site).filter(Site.site_id == site_slug).first()
if not site:
raise HTTPException(status_code=404, detail="Site not found")
@@ -48,6 +49,13 @@ def get_menu(site_slug: str, db: Session = Depends(get_db)):
from services.ordering import summary
data["ordering"] = summary(data) # S.4: services, open now, slots
data["menu_mode"] = site.menu_mode
from services import qr
data["table_ordering"] = qr.ordering_on(data, site) # S.7: ordering at the table (with a table's QR)
if t is not None:
table = qr.table_for(data, t)
data["table"] = table
data["table_invalid"] = table is None
data.pop("qr", None) # the tables' token hashes stay on the cloud
data["restaurant"] = {
"name": site.menu_display_name,
"tagline": {"en": site.menu_tagline_en, "gr": site.menu_tagline_gr},
+10 -2
View File
@@ -14,7 +14,7 @@ from schemas.online_order import (
PendingOrderOut, OrderSyncedRequest, OrderStatusUpdateRequest, QuoteRequest,
)
from services.checkout import CheckoutError, check_sent, price_cart
from services import ordering, ratelimit
from services import ordering, qr, ratelimit
# public endpoints, per caller address (CL-4)
QUOTE_LIMIT = (120, 60) # 120 quotes a minute
@@ -115,6 +115,13 @@ def create_order(site_slug: str, body: OnlineOrderCreate, request: Request, db:
site, menu = _site_and_menu(db, site_slug)
items = [i.model_dump() for i in body.items]
reservation = body.order_type in ordering.RES_TYPES # S.6: a table, maybe with food
table = None
if body.order_type == "dine_in": # S.7: only from a table's QR code
if not qr.ordering_on(menu, site):
raise HTTPException(status_code=409, detail={"code": "order.service_unavailable", "params": {"service": "dine_in"}})
table = qr.table_for(menu, body.table_token)
if table is None:
raise HTTPException(status_code=403, detail={"code": "order.table_invalid", "params": {}})
if body.order_type == "reservation":
if items:
raise HTTPException(status_code=422, detail={"code": "order.items_not_allowed", "params": {}})
@@ -151,7 +158,8 @@ def create_order(site_slug: str, body: OnlineOrderCreate, request: Request, db:
customer_phone=body.customer_phone,
customer_address=body.customer_address,
customer_notes=body.customer_notes,
table_label=(body.customer_table or "").strip() or None,
table_label=table["label"] if table else None,
table_id=table["id"] if table else None,
delivery_area=priced.area_name if priced else None,
delivery_area_id=priced.area_id if priced else None,
# stored as UTC: SQLite keeps no time zone (read back naive = UTC, schemas mark it)