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>
115 lines
4.3 KiB
Python
115 lines
4.3 KiB
Python
from __future__ import annotations
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from datetime import timezone
|
|
|
|
from pydantic import BaseModel, Field, field_serializer
|
|
|
|
|
|
def _utc(value):
|
|
"""The cloud's database keeps no time zone: a naive datetime is UTC. Sent with its offset."""
|
|
if value is None:
|
|
return None
|
|
return (value.replace(tzinfo=timezone.utc) if value.tzinfo is None else value).isoformat()
|
|
|
|
|
|
class OrderItemIn(BaseModel):
|
|
"""What the customer wants. Prices come from the venue's menu (services/checkout.py);
|
|
name and unit_price, if sent, are only compared (phase 3S, S.2)."""
|
|
product_id: int
|
|
quantity: int
|
|
name: Optional[str] = None
|
|
unit_price: Optional[float] = None
|
|
options: list = [] # quick option ids (or {id})
|
|
|
|
|
|
class QuoteRequest(BaseModel):
|
|
order_type: str # dine_in | takeaway | delivery | preorder
|
|
items: list[OrderItemIn] = Field(max_length=100)
|
|
area_id: Optional[int] = None # the delivery area picked (S.3)
|
|
postcode: Optional[str] = Field(default=None, max_length=20)
|
|
|
|
|
|
class OnlineOrderCreate(BaseModel):
|
|
order_type: str # dine_in | takeaway | delivery | reservation | preorder
|
|
customer_name: str = Field(min_length=1, max_length=100)
|
|
party_size: Optional[int] = None # reservations (S.6)
|
|
customer_phone: Optional[str] = Field(default=None, max_length=40)
|
|
customer_address: Optional[str] = Field(default=None, max_length=500)
|
|
customer_notes: Optional[str] = Field(default=None, max_length=1000)
|
|
customer_table: Optional[str] = Field(default=None, max_length=40) # ignored since S.7 (the token says)
|
|
table_token: Optional[str] = Field(default=None, max_length=100) # the table's QR token (S.7)
|
|
area_id: Optional[int] = None # the delivery area picked (S.3)
|
|
postcode: Optional[str] = Field(default=None, max_length=20)
|
|
requested_for: Optional[datetime] = None # a time slot (S.4); None = as soon as possible
|
|
items: list[OrderItemIn] = Field(default_factory=list, max_length=100)
|
|
# what the customer was shown: compared, never stored as sent
|
|
subtotal: Optional[float] = None
|
|
delivery_fee: Optional[float] = None
|
|
total: Optional[float] = None
|
|
|
|
|
|
class OnlineOrderCreated(BaseModel):
|
|
order_id: int
|
|
public_ref: str
|
|
status: str
|
|
tracking_token: Optional[str] = None # the tracking page: GET /api/orders/track/{token} (S.2)
|
|
total: Optional[float] = None
|
|
|
|
|
|
class OrderStatusOut(BaseModel):
|
|
public_ref: str
|
|
status: str
|
|
rejection_reason: Optional[str] = None
|
|
# S.4: what the tracking page shows (all optional: older clients ignore them)
|
|
order_type: Optional[str] = None
|
|
requested_for: Optional[datetime] = None
|
|
party_size: Optional[int] = None # reservations (S.6)
|
|
created_at: Optional[datetime] = None
|
|
lines: Optional[list] = None
|
|
subtotal: Optional[float] = None
|
|
delivery_fee: Optional[float] = None
|
|
total: Optional[float] = None
|
|
|
|
@field_serializer('requested_for', 'created_at')
|
|
def _times(self, value):
|
|
return _utc(value)
|
|
|
|
|
|
class PendingOrderOut(BaseModel):
|
|
id: int
|
|
public_ref: str
|
|
order_type: str
|
|
customer_name: str
|
|
customer_phone: Optional[str] = None
|
|
customer_address: Optional[str] = None
|
|
customer_notes: Optional[str] = None
|
|
table_label: Optional[str] = None # the QR menu's table (S.2)
|
|
table_id: Optional[int] = None # the site's table, from a valid QR token (S.7)
|
|
delivery_area: Optional[str] = None # the delivery area's name (S.3)
|
|
delivery_area_id: Optional[int] = None # the site's area id (S.5)
|
|
requested_for: Optional[datetime] = None # when the customer wants it (S.4); None = as soon as possible
|
|
party_size: Optional[int] = None # reservations (S.6)
|
|
sales_point: Optional[str] = None # the site's sales point (S.2)
|
|
items_json: str
|
|
subtotal: float
|
|
delivery_fee: float
|
|
total: float
|
|
status: str
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
@field_serializer('requested_for', 'created_at')
|
|
def _times(self, value):
|
|
return _utc(value)
|
|
|
|
|
|
class OrderSyncedRequest(BaseModel):
|
|
local_order_id: int
|
|
|
|
|
|
class OrderStatusUpdateRequest(BaseModel):
|
|
status: str
|
|
rejection_reason: Optional[str] = None
|