feat(cloud): table bookings online, with food ordered ahead
Plan phase 3S, step S.6.
- New order types "reservation" (a table only, no items) and "preorder" (a table with food,
priced at the online_preorder sales point); online_orders.party_size (migration 0005).
- services/ordering.py: the venue's booking settings (ordering.reservations in the snapshot):
hours (none = any time), time grid, notice, days ahead (≤ 90), party size; res_slots per
venue day, res_days, res_check (order.service_unavailable, order.party_invalid,
order.time_invalid). The public menu's ordering summary gains `reservations`
{enabled, with_food, party_max, days}; GET /api/orders/{site}/reservation-slots?day=.
- Bookings need a phone; a plain booking refuses items (order.items_not_allowed).
- Status steps for bookings: pending_acceptance → accepted | rejected; accepted → delivered
(arrived) | cancelled (by the venue); ordinary orders unchanged.
- Order app: "Book a table" (people, day, time, optional food at the pre-order prices),
booking summary at checkout, a booking tracking page (waiting, confirmed, welcome;
declined / cancelled with the reason). en/el.
- Tests: tests/test_reservations.py (3), order-app logic test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,7 +89,8 @@ def summary(snapshot: dict, now: datetime | None = None) -> dict:
|
||||
open_now = is_open(cfg, local_now)
|
||||
return {"services": cfg["services"], "open_now": open_now, "asap": bool(cfg["asap"]) and open_now,
|
||||
"prep_minutes": cfg["prep_minutes"], "timezone": tz.key,
|
||||
"slots": [t.isoformat() for t in slots(snapshot, now)]}
|
||||
"slots": [t.isoformat() for t in slots(snapshot, now)],
|
||||
"reservations": res_summary(snapshot, now)} # S.6
|
||||
|
||||
|
||||
def check(snapshot: dict, service: str, requested_for: datetime | None, now: datetime | None = None):
|
||||
@@ -109,3 +110,76 @@ def check(snapshot: dict, service: str, requested_for: datetime | None, now: dat
|
||||
if any(abs((wanted - t).total_seconds()) < 1 for t in slots(snapshot, now)):
|
||||
return None
|
||||
return "order.time_invalid", {}
|
||||
|
||||
|
||||
# ── Reservations online (plan phase 3S, step S.6) ─────────────────────────────
|
||||
# The snapshot's `ordering.reservations` (site routers/fees.py ReservationsBody):
|
||||
# {enabled, with_food, hours: {"0".."6": [[from, to], ...]}, slot_minutes, days_ahead,
|
||||
# notice_minutes, party_max, fire_minutes}
|
||||
# "reservation" = a table only; "preorder" = a table with food ready on arrival (with_food).
|
||||
# Times: on the slot grid of the venue's day, at least notice_minutes from now, within today +
|
||||
# days_ahead, inside the hours (none = any time). fire_minutes is the site's (the kitchen).
|
||||
|
||||
RES_DEFAULTS = {"enabled": False, "with_food": False, "hours": {}, "slot_minutes": 30, "days_ahead": 30,
|
||||
"notice_minutes": 60, "party_max": 10}
|
||||
RES_TYPES = ("reservation", "preorder")
|
||||
|
||||
|
||||
def res_config(snapshot: dict) -> dict:
|
||||
cfg = {**RES_DEFAULTS, **((snapshot.get("ordering") or {}).get("reservations") or {})}
|
||||
cfg["enabled"] = bool(cfg.get("enabled"))
|
||||
cfg["with_food"] = cfg["enabled"] and bool(cfg.get("with_food"))
|
||||
cfg["slot_minutes"] = max(5, int(cfg.get("slot_minutes") or 30))
|
||||
cfg["days_ahead"] = max(0, min(90, int(cfg.get("days_ahead") or 0)))
|
||||
cfg["notice_minutes"] = max(0, int(cfg.get("notice_minutes") or 0))
|
||||
cfg["party_max"] = max(1, min(100, int(cfg.get("party_max") or 1)))
|
||||
return cfg
|
||||
|
||||
|
||||
def res_slots(snapshot: dict, day, now: datetime | None = None) -> list[datetime]:
|
||||
"""The reservation times on one venue day (a date), aware venue local, in order."""
|
||||
cfg, tz = res_config(snapshot), venue_tz(snapshot)
|
||||
if not cfg["enabled"]:
|
||||
return []
|
||||
local_now = (now or datetime.now(timezone.utc)).astimezone(tz)
|
||||
if day < local_now.date() or day > (local_now + timedelta(days=cfg["days_ahead"])).date():
|
||||
return []
|
||||
earliest = local_now + timedelta(minutes=cfg["notice_minutes"])
|
||||
t = datetime(day.year, day.month, day.day, tzinfo=tz)
|
||||
out = []
|
||||
while t.date() == day:
|
||||
if t >= earliest and is_open(cfg, t):
|
||||
out.append(t)
|
||||
t = (t.astimezone(timezone.utc) + timedelta(minutes=cfg["slot_minutes"])).astimezone(tz)
|
||||
return out
|
||||
|
||||
|
||||
def res_days(snapshot: dict, now: datetime | None = None) -> list[str]:
|
||||
"""The venue days (ISO dates) with at least one reservation time."""
|
||||
cfg, tz = res_config(snapshot), venue_tz(snapshot)
|
||||
if not cfg["enabled"]:
|
||||
return []
|
||||
today = (now or datetime.now(timezone.utc)).astimezone(tz).date()
|
||||
days = (today + timedelta(days=n) for n in range(cfg["days_ahead"] + 1))
|
||||
return [d.isoformat() for d in days if res_slots(snapshot, d, now)]
|
||||
|
||||
|
||||
def res_summary(snapshot: dict, now: datetime | None = None) -> dict:
|
||||
cfg = res_config(snapshot)
|
||||
return {"enabled": cfg["enabled"], "with_food": cfg["with_food"], "party_max": cfg["party_max"],
|
||||
"days": res_days(snapshot, now)}
|
||||
|
||||
|
||||
def res_check(snapshot: dict, order_type: str, requested_for: datetime | None, party_size, now: datetime | None = None):
|
||||
"""None if the reservation may be requested, else (code, params)."""
|
||||
cfg = res_config(snapshot)
|
||||
if not cfg["enabled"] or (order_type == "preorder" and not cfg["with_food"]):
|
||||
return "order.service_unavailable", {"service": order_type}
|
||||
if isinstance(party_size, bool) or not isinstance(party_size, int) or not 1 <= party_size <= cfg["party_max"]:
|
||||
return "order.party_invalid", {"max": cfg["party_max"]}
|
||||
if requested_for is None or requested_for.tzinfo is None:
|
||||
return "order.time_invalid", {}
|
||||
wanted = requested_for.astimezone(venue_tz(snapshot))
|
||||
if any(abs((wanted - t).total_seconds()) < 1 for t in res_slots(snapshot, wanted.date(), now)):
|
||||
return None
|
||||
return "order.time_invalid", {}
|
||||
|
||||
Reference in New Issue
Block a user