feat(cloud): delivery fees and minimum orders at checkout (platform-v2 3S, S.3)

- services/fees.py: the site's fee engine, byte-identical (the site's tests check it);
  tests/fixtures/fee_cases.json: the shared cases, run here too.
- checkout: the snapshot's fees (areas, rules) at the venue's time zone; refused
  order.area_not_served / order.minimum_not_met {minimum, subtotal}; quote and order take
  area_id / postcode and return area_name, fee_rules; the order stores delivery_area.
- GET /api/menu/{site}: delivery_areas [{id, name}] for the customer; the rules and
  postcodes are never sent to the browser.
- Alembic 0003 (unreleased) gains online_orders.delivery_area.
- Tests: test_fees.py (22 shared cases + checkout fees, refusals, public menu, clock).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 12:28:15 +02:00
co-authored by Claude Opus 5.5
parent 5bdd19d9fb
commit 96f16e948d
9 changed files with 387 additions and 10 deletions
+5 -4
View File
@@ -51,9 +51,9 @@ def _site_and_menu(db, site_slug):
return site, json.loads(snap.snapshot_json)
def _priced(menu, order_type, items):
def _priced(menu, order_type, items, area_id=None, postcode=None):
try:
return price_cart(menu, order_type, items)
return price_cart(menu, order_type, items, area_id=area_id, postcode=postcode)
except CheckoutError as e:
raise HTTPException(status_code=e.status, detail=e.detail())
@@ -62,7 +62,7 @@ def _priced(menu, order_type, items):
def quote_order(site_slug: str, body: QuoteRequest, db: Session = Depends(get_db)):
"""The cart priced by the cloud from the venue's menu, for the customer apps (phase 3S)."""
_site, menu = _site_and_menu(db, site_slug)
return _priced(menu, body.order_type, [i.model_dump() for i in body.items]).out()
return _priced(menu, body.order_type, [i.model_dump() for i in body.items], body.area_id, body.postcode).out()
@router.post("/{site_slug}", response_model=OnlineOrderCreated, status_code=status.HTTP_201_CREATED)
@@ -73,7 +73,7 @@ def create_order(site_slug: str, body: OnlineOrderCreate, db: Session = Depends(
money is stored (phase 3S, S.2)."""
site, menu = _site_and_menu(db, site_slug)
items = [i.model_dump() for i in body.items]
priced = _priced(menu, body.order_type, items)
priced = _priced(menu, body.order_type, items, body.area_id, body.postcode)
try:
check_sent(priced, items, body.total)
except CheckoutError as e:
@@ -94,6 +94,7 @@ def create_order(site_slug: str, body: OnlineOrderCreate, db: Session = Depends(
customer_address=body.customer_address,
customer_notes=body.customer_notes,
table_label=(body.customer_table or "").strip() or None,
delivery_area=priced.area_name,
sales_point=priced.sales_point,
items_json=json.dumps([line.out() for line in priced.lines]),
subtotal=priced.subtotal,