- models/fees.py + Alembic 0018: delivery_areas, fee_rules; key connect_orders.fees (owner, store manager; existing ones get it). - services/fees.py: the pure engine (set / add / % / free / minimum, conditions: sales points, areas, products total, item count, days, time incl. past midnight, stop), the same file as the cloud's; tests/fixtures/fee_cases.json shared, plus a test that the cloud copy is identical. - routers/fees.py at /api/connect/fees: areas and rules CRUD (validated), order, preview. - Snapshot carries fees + the venue's time zone; a change to products, pricing or fees pushes the menu within ~5 s (middleware -> cloud_sync.request_menu_push). - Manager: Online -> Delivery fees page (@xenia/ui): rules in order with words for each, areas with postcodes, "Test an order"; en/el texts; feesLogic.js unit-tested. - Tests: test_fees.py (39), manager unit +5, manager.mjs +7 on the real page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
2.3 KiB
Python
47 lines
2.3 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) 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
|
|
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)
|