Files
xenia-pos-local/local_backend/models/reservation.py
T
bonaminandClaude Opus 5.5 70c8f2bb57 feat(connect): table bookings from the online ordering app; food fired to the kitchen before arrival
Plan phase 3S, step S.6.
- Pull: "reservation" / "preorder" orders become Reservations waiting for an answer
  (status "requested"; services/online_reservations.py), with the food ordered ahead kept on
  the booking (items_json at the cloud's prices, the site's price check) — no order yet.
  Migration 0020 (reservations: online_order_cloud_id, online_ref, items_json, total,
  online_price_diff, fire_at, order_id, response_note).
- Confirm → the food's fire time = booking time − fire minutes (setting); the fire worker
  (connect_orders, every 20 s) turns the food into an order at that time (needs an open
  business day; waits otherwise): kitchen tickets, KDS (reference and time). Early arrival
  fires at once. Seating moves the order to the table (refused if the table has an open
  order). Decline / cancel / no-show with a reason. Every step mirrored to the cloud.
- Found: the KDS filter dropped every online order without an online status (SQL NULL in
  NOT(a AND b)) — made NULL-safe.
- Counter: Online → Bookings (requests first, then upcoming), BookingPanel (confirm,
  decline with reasons, food and when it goes to the kitchen, seat at a free table, cancel,
  no-show); the Online badge and chime count booking requests.
- Manager: Online ordering → Table bookings settings (on, food ahead, hours, slot, notice,
  days ahead, party size, fire minutes); the dashboard's reservations card confirms /
  declines online requests; the reservations router delegates online bookings' status steps.
- Tests: tests/test_online_bookings.py (8), unit tests (terminal, manager), e2e: order app
  (book with food → the venue confirms), terminal (request → confirm → the two dishes reach
  the KDS at the fire time, not before → seated), manager (booking settings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 19:31:44 +02:00

56 lines
2.6 KiB
Python

from sqlalchemy import Column, Float, Integer, String, ForeignKey, Text
from core.timeutil import UTCDateTime, utcnow
from sqlalchemy.orm import relationship
from database import Base
class Reservation(Base):
__tablename__ = "reservations"
id = Column(Integer, primary_key=True, index=True)
# Guest info
guest_name = Column(String, nullable=False)
party_size = Column(Integer, nullable=False)
phone = Column(String, nullable=True)
email = Column(String, nullable=True)
note = Column(Text, nullable=True)
# When the customer wants the table
reserved_for = Column(UTCDateTime, nullable=False)
# Optional table assignment (assignable/editable later)
table_id = Column(Integer, ForeignKey("tables.id"), nullable=True)
# Lifecycle: pending (confirmed, upcoming) | arrived | cancelled | no_show;
# online requests (phase 3S, S.6) start as requested → pending (confirmed) | declined
status = Column(String, nullable=False, default="pending")
# Source: manager_app | waiter_app | online
source = Column(String, nullable=False, default="manager_app")
# Who entered this reservation (staff user)
created_by_user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
# For future online reservations: cloud-side customer identifier
online_customer_id = Column(String, nullable=True)
# Online bookings (phase 3S, S.6): the cloud's order (status mirrored to the customer's page)
online_order_cloud_id = Column(Integer, nullable=True, index=True)
online_ref = Column(String, nullable=True) # "ORD-0042"
# food ordered ahead: the cloud's lines (its prices) until the kitchen gets them, then the order
items_json = Column(Text, nullable=True) # JSON list as the cloud sent it; NULL = a table only
total = Column(Float, nullable=True)
online_price_diff = Column(Text, nullable=True) # services/online_check.py; NULL = matched
fire_at = Column(UTCDateTime, nullable=True) # when the kitchen gets the food (set on confirming)
order_id = Column(Integer, ForeignKey("orders.id"), nullable=True) # created at fire time
response_note = Column(Text, nullable=True) # why it was declined / cancelled (the customer sees it)
created_at = Column(UTCDateTime, default=utcnow)
updated_at = Column(UTCDateTime, default=utcnow,
onupdate=utcnow)
table = relationship("Table", foreign_keys=[table_id])
order = relationship("Order", foreign_keys=[order_id])
created_by = relationship("User", foreign_keys=[created_by_user_id])