feat(cloud): the cloud prices online orders itself; sites only touch their own data (platform-v2 3S, S.2)
- services/checkout.py: orders and quotes priced from the site's snapshot per sales point
(prices map; older snapshots: digital_price less discount); refused: unavailable or
not sold there, bad quantity/option/type, empty, order.price_changed when the browser's
unit price or total differs. Nothing the browser says about money is stored.
- POST /api/orders/{site}/quote; delivery needs phone + address.
- Fixes: pending orders, menu sync and stats snapshot acted on the site_id given, not the
authenticated site (a site could read another's orders or overwrite its menu/stats).
- Order refs are unique per site (a second site's first order failed); tracking by a
random token GET /api/orders/track/{token}; old /status/{ref} only while unambiguous.
- Alembic 0003: online_orders sales_point, table_label, tracking_token; table rebuilt.
- menu-app: tracking link uses the token, shows the order number; tells the customer when
the menu changed or the order failed.
- Tests: test_checkout.py (6), 0003 data migration.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,33 +1,44 @@
|
||||
from __future__ import annotations
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
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
|
||||
name: str
|
||||
quantity: int
|
||||
unit_price: float
|
||||
options: list = []
|
||||
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)
|
||||
|
||||
|
||||
class OnlineOrderCreate(BaseModel):
|
||||
order_type: str # "delivery" | "dine_in"
|
||||
customer_name: str
|
||||
customer_phone: Optional[str] = None
|
||||
customer_address: Optional[str] = None
|
||||
customer_notes: Optional[str] = None
|
||||
items: list[OrderItemIn]
|
||||
subtotal: float
|
||||
delivery_fee: float = 0.0
|
||||
total: float
|
||||
order_type: str # dine_in | takeaway | delivery | preorder
|
||||
customer_name: str = Field(min_length=1, max_length=100)
|
||||
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)
|
||||
items: list[OrderItemIn] = Field(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):
|
||||
@@ -44,6 +55,8 @@ class PendingOrderOut(BaseModel):
|
||||
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)
|
||||
sales_point: Optional[str] = None # the site's sales point (S.2)
|
||||
items_json: str
|
||||
subtotal: float
|
||||
delivery_fee: float
|
||||
|
||||
Reference in New Issue
Block a user