feat: delivery areas drawn on a map (plan 6R.G)

An area is a list of postcodes, a shape drawn on a map or a circle around a
point. The fee engine (both copies, byte-identical) matches a shape only by
the customer's pin, then postcodes; point-in-polygon (edges inside) and
haversine circles; shared cases in fee_cases.json.

- Alembic 0053: delivery_areas.kind / geometry, orders.online_lat / lng
- /api/connect/fees: areas with kind + geometry (validated: 3-200 corners,
  50 m - 50 km), the venue's place (PUT /venue-point, setting venue.location,
  sent to the cloud as fees.venue_point), preview by lat / lng
- manager: DeliveryMap (Leaflet + OpenStreetMap tiles): draw / move / remove
  corners, circles, the venue on the map, an overview, test an order by a point
- pulled online orders keep the pin; the site re-checks the fee with it;
  the counter links the pin to a map
- tests: backend (shapes, venue point, pinned orders), manager logic,
  e2e manager.mjs and order_app.mjs 6R.G blocks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 21:55:36 +02:00
co-authored by Claude Opus 5.5
parent 0840247768
commit 6f42e00684
25 changed files with 844 additions and 40 deletions
+9 -1
View File
@@ -22,6 +22,13 @@ from datetime import datetime
EPS = 0.005
def pin_of(cloud_order) -> list | None:
"""The customer's pin [lat, lng] (6R.G), when the order has one."""
lat, lng = cloud_order.get("lat"), cloud_order.get("lng")
ok = all(isinstance(x, (int, float)) and not isinstance(x, bool) for x in (lat, lng))
return [float(lat), float(lng)] if ok else None
def _when(cloud_order: dict):
from core.timeutil import utcnow
raw = cloud_order.get("created_at")
@@ -76,7 +83,8 @@ def diff(db, cloud_order: dict, sales_point: str) -> dict | None:
subtotal=round(float(cloud_order.get("subtotal") or 0.0), 2),
items=sum(int(i.get("quantity", 1) or 1) for i in items),
area_id=cloud_order.get("delivery_area_id"), postcode=None,
weekday=local.weekday(), hhmm=local.strftime("%H:%M"))
weekday=local.weekday(), hhmm=local.strftime("%H:%M"),
point=pin_of(cloud_order)) # 6R.G: a drawn area needs the pin
if result["refused"]:
fee = {"cloud": cloud_fee, "site": None,
"reason": "area" if result["refused"] == "area_not_served" else "minimum"}