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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user