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:
@@ -89,9 +89,24 @@ def venue_clock(snapshot: dict, now: datetime | None = None) -> tuple[int, str]:
|
||||
|
||||
|
||||
def delivery_areas(snapshot: dict) -> list:
|
||||
"""The active areas a customer picks from: [{id, name}] (no postcodes, no rules)."""
|
||||
return [{"id": a.get("id"), "name": a.get("name")} for a in (snapshot.get("fees") or {}).get("areas") or []
|
||||
if a.get("is_active", True)]
|
||||
"""The active areas: [{id, name, kind}] (no postcodes, no rules). A postcode area is picked
|
||||
from a list; a shape (6R.G: polygon / circle) also gives its geometry, so the customer's map
|
||||
can draw where the venue delivers; the cloud matches it by the customer's pin."""
|
||||
out = []
|
||||
for a in (snapshot.get("fees") or {}).get("areas") or []:
|
||||
if not a.get("is_active", True):
|
||||
continue
|
||||
kind = a.get("kind") or "postcodes"
|
||||
item = {"id": a.get("id"), "name": a.get("name"), "kind": kind}
|
||||
if kind in fee_engine.SHAPES:
|
||||
item["geometry"] = a.get("geometry")
|
||||
out.append(item)
|
||||
return out
|
||||
|
||||
|
||||
def venue_point(snapshot: dict):
|
||||
"""The venue's place on the map (6R.G): {lat, lng} or None; the customer's map starts there."""
|
||||
return (snapshot.get("fees") or {}).get("venue_point")
|
||||
|
||||
|
||||
def products_of(snapshot: dict) -> dict[int, dict]:
|
||||
@@ -135,9 +150,9 @@ def _option_ids(raw) -> list:
|
||||
|
||||
|
||||
def price_cart(snapshot: dict, order_type: str, items: list[dict], area_id=None, postcode=None,
|
||||
now: datetime | None = None) -> Priced:
|
||||
now: datetime | None = None, pin=None) -> Priced:
|
||||
"""Price the cart from the snapshot. items: [{product_id, quantity, options?}]; the
|
||||
customer's area (picked, or by postcode) for the fee."""
|
||||
customer's area (picked, by their `pin` [lat, lng] on the map (6R.G), or by postcode) for the fee."""
|
||||
point = POINT_FOR_TYPE.get(order_type)
|
||||
if point is None:
|
||||
raise CheckoutError(422, "order.type_invalid", order_type=order_type)
|
||||
@@ -170,7 +185,8 @@ def price_cart(snapshot: dict, order_type: str, items: list[dict], area_id=None,
|
||||
weekday, hhmm = venue_clock(snapshot, now)
|
||||
result = fee_engine.compute(rules.get("rules") or [], rules.get("areas") or [], sales_point=point,
|
||||
subtotal=subtotal, items=sum(x.quantity for x in lines),
|
||||
area_id=area_id, postcode=postcode, weekday=weekday, hhmm=hhmm)
|
||||
area_id=area_id, postcode=postcode, weekday=weekday, hhmm=hhmm,
|
||||
point=pin)
|
||||
if result["refused"] == "area_not_served":
|
||||
raise CheckoutError(409, "order.area_not_served", postcode=postcode, area_id=area_id)
|
||||
if result["refused"] == "minimum_not_met":
|
||||
|
||||
Reference in New Issue
Block a user