feat: delivery areas and fee rules with "test an order" (platform-v2 3S, S.3)
- 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>
This commit is contained in:
@@ -34,4 +34,5 @@ import models.device # noqa: F401 Device, DevicePairRequest (step 1.8)
|
||||
import models.access_override # noqa: F401 AccessOverride (manager override, step 1.9)
|
||||
import models.support_challenge # noqa: F401 SupportChallenge (support access, step 1.10)
|
||||
import models.notification # noqa: F401 Notification, NotificationRead (step 1.11)
|
||||
import models.fees # noqa: F401 DeliveryArea, FeeRule (phase 3S, S.3)
|
||||
import models.refund # noqa: F401 Refund, RefundItem (step 3.3e)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
"""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)
|
||||
Reference in New Issue
Block a user