feat: delivery areas drawn on a map: the customer pins the address (plan 6R.G)

- services/fees.py: the site's engine (shapes matched by the pin), shared cases
- checkout: price_cart(pin=), delivery_areas with kind (+ geometry for shapes),
  venue_point in the public menu (postcodes and rules stay on the cloud)
- orders: quote / create take lat / lng; online_orders.lat / lng (Alembic 0007),
  sent to the site with the pending orders
- order app: PinMap (Leaflet + OpenStreetMap tiles), 'Pin it on the map' first
  when the venue drew areas, the browser's location offered; lat / lng sent
- tests: cloud test_fees (pinned quote and order), order-app logic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 21:56:13 +02:00
co-authored by Claude Opus 5.5
parent e55157fa86
commit d5b8492512
17 changed files with 406 additions and 41 deletions
+3 -2
View File
@@ -43,8 +43,9 @@ def get_menu(site_slug: str, t: str | None = None, db: Session = Depends(get_db)
import json
data = json.loads(snapshot.snapshot_json)
from services.checkout import delivery_areas
data["delivery_areas"] = delivery_areas(data) # S.3: what the customer picks from
from services.checkout import delivery_areas, venue_point
data["delivery_areas"] = delivery_areas(data) # S.3: what the customer picks from (6R.G: shapes drawn)
data["venue_point"] = venue_point(data) # 6R.G: where the customer's map starts
data.pop("fees", None) # the rules and postcodes stay on the cloud
from services.ordering import summary
data["ordering"] = summary(data) # S.4: services, open now, slots
+11 -4
View File
@@ -72,9 +72,14 @@ def _site_and_menu(db, site_slug):
return site, json.loads(snap.snapshot_json)
def _priced(menu, order_type, items, area_id=None, postcode=None):
def _pin(body):
"""The customer's pin [lat, lng] (6R.G), both or nothing."""
return [body.lat, body.lng] if body.lat is not None and body.lng is not None else None
def _priced(menu, order_type, items, area_id=None, postcode=None, point=None):
try:
return price_cart(menu, order_type, items, area_id=area_id, postcode=postcode)
return price_cart(menu, order_type, items, area_id=area_id, postcode=postcode, pin=point)
except CheckoutError as e:
raise HTTPException(status_code=e.status, detail=e.detail())
@@ -102,7 +107,7 @@ def quote_order(site_slug: str, body: QuoteRequest, request: Request, db: Sessio
"""The cart priced by the cloud from the venue's menu, for the customer apps (phase 3S)."""
_limit(request, "quote", QUOTE_LIMIT)
_site, menu = _site_and_menu(db, site_slug)
return _priced(menu, body.order_type, [i.model_dump() for i in body.items], body.area_id, body.postcode).out()
return _priced(menu, body.order_type, [i.model_dump() for i in body.items], body.area_id, body.postcode, _pin(body)).out()
@router.post("/{site_slug}", response_model=OnlineOrderCreated, status_code=status.HTTP_201_CREATED)
@@ -127,7 +132,7 @@ def create_order(site_slug: str, body: OnlineOrderCreate, request: Request, db:
raise HTTPException(status_code=422, detail={"code": "order.items_not_allowed", "params": {}})
priced = None
else:
priced = _priced(menu, body.order_type, items, body.area_id, body.postcode)
priced = _priced(menu, body.order_type, items, body.area_id, body.postcode, _pin(body))
if reservation:
problem = ordering.res_check(menu, body.order_type, body.requested_for, body.party_size)
elif body.order_type in ("takeaway", "delivery"): # the online ordering app (S.4)
@@ -162,6 +167,8 @@ def create_order(site_slug: str, body: OnlineOrderCreate, request: Request, db:
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,
lat=body.lat if body.order_type == "delivery" and _pin(body) else None,
lng=body.lng if body.order_type == "delivery" and _pin(body) else None,
# stored as UTC: SQLite keeps no time zone (read back naive = UTC, schemas mark it)
requested_for=(body.requested_for.astimezone(timezone.utc).replace(tzinfo=None)
if (reservation or body.order_type in ("takeaway", "delivery")) and body.requested_for else None),