Files
xenia-pos-local/local_backend/models/fees.py
T
bonaminandClaude Opus 5.5 6f42e00684 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>
2026-11-23 21:55:36 +02:00

50 lines
2.6 KiB
Python

"""Delivery areas and fee rules (plan phase 3S, step S.3).
The venue lists the areas it delivers to (by name, with postcodes when it wants the customer's
postcode matched, or since 6R.G a shape drawn on a map / a circle, matched by the customer's pin) and fee rules evaluated in order by services/fees.py — the same engine the
cloud runs at checkout (the rules travel with the menu snapshot). See that module for the
rule semantics.
"""
from sqlalchemy import Column, Float, Integer, String, Text
from core.timeutil import UTCDateTime, utcnow
from database import Base
class DeliveryArea(Base):
__tablename__ = "delivery_areas"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
postcodes = Column(Text, nullable=False, default="[]") # JSON list of strings
# 6R.G: postcodes | polygon | circle; geometry JSON: [[lat, lng], …] or {center: [lat, lng], radius_m}
kind = Column(String, nullable=False, default="postcodes", server_default="postcodes")
geometry = Column(Text, nullable=True)
is_active = Column(Integer, nullable=False, default=1)
sort_order = Column(Integer, nullable=False, default=0)
created_at = Column(UTCDateTime, default=utcnow)
class FeeRule(Base):
__tablename__ = "fee_rules"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
is_active = Column(Integer, nullable=False, default=1)
sort_order = Column(Integer, nullable=False, default=0)
# conditions (empty / null = any)
sales_points = Column(Text, nullable=False, default='["online_delivery"]') # JSON list
area_ids = Column(Text, nullable=False, default="[]") # JSON list of ints
subtotal_min = Column(Float, nullable=True) # products total >= this
subtotal_max = Column(Float, nullable=True) # products total < this
items_min = Column(Integer, nullable=True) # number of items >= this
items_max = Column(Integer, nullable=True) # number of items <= this
days = Column(Text, nullable=False, default="[]") # JSON list, Mon=0 … Sun=6
time_from = Column(String, nullable=True) # "HH:MM", venue time
time_to = Column(String, nullable=True) # "HH:MM"; before time_from = crosses midnight
# what it does: set | add | percent | free | minimum
action = Column(String, nullable=False, default="set")
value = Column(Float, nullable=False, default=0.0)
stop = Column(Integer, nullable=False, default=0) # no later rule is looked at once this one applies
created_at = Column(UTCDateTime, default=utcnow)