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
@@ -176,3 +176,25 @@ def test_the_venues_ordering_link(client, owner_h, monkeypatch):
monkeypatch.setattr(cloud_sync.settings, "SITE_ID", "taverna-1")
links = client.get("/api/connect/fees", headers=owner_h).json()["links"]
assert links == {"order": "https://menu.example.com/order/taverna-1", "menu": "https://menu.example.com/menu/taverna-1"}
def test_a_pinned_delivery_keeps_its_pin_and_is_checked_by_it(client, db, counter, menu):
"""6R.G: an order priced by a drawn area: the site checks the fee with the pin (a shape is
matched only by a point inside it), keeps the pin for a map link on the counter."""
from models.fees import DeliveryArea, FeeRule
from models.order import Order
drawn = DeliveryArea(name="Drawn", kind="polygon", postcodes="[]", is_active=1, sort_order=0,
geometry=json.dumps([[37.0, 22.0], [37.0, 22.1], [37.1, 22.1], [37.1, 22.0]]))
db.add(drawn)
db.flush()
db.add(FeeRule(name="Drawn", is_active=1, sort_order=0, sales_points=json.dumps(["online_delivery"]),
area_ids=json.dumps([drawn.id]), action="set", value=2.5, stop=1))
db.commit()
oid = pull(db, menu, cloud_id=611, area_id=drawn.id, area="Drawn", lat=37.05, lng=22.05)
order = db.get(Order, oid)
assert order.online_price_diff is None and (order.online_lat, order.online_lng) == (37.05, 22.05)
assert next(x for x in board(client, counter)["incoming"] if x["id"] == oid)["pin"] == {"lat": 37.05, "lng": 22.05}
# no pin: the site can't place it in the drawn area, and says so (the customer keeps the cloud's fee)
oid = pull(db, menu, cloud_id=612, area_id=drawn.id, area="Drawn")
assert json.loads(db.get(Order, oid).online_price_diff)["fee"]["reason"] == "area"
assert next(x for x in board(client, counter)["incoming"] if x["id"] == oid)["pin"] is None