feat: tables and orders in the manager on v2 (platform-v2 step 6.9)

- manager: new pages/orders/ (Tables page cards + quick actions, order page with
  lines, multi-select pay/discount/cancel/tab, staff + customer, price changes,
  history, the menu + cart beside it); a free table opens a new order on first
  Send; v1 TablesPage, OrderDetailPage, DesktopOrderingTab, ManagerOrderDrawer
  and PaymentMethodModal removed
- ordering by line id like the phones: GET /api/orders/menu (the counter's
  product shape, in-store prices); the product dialog, cart rules and quote hook
  move to packages/ordering (@xenia/ordering), shared by counter, menu tablet,
  manager
- close follows orders.close_with_unpaid (pay first, or write off after saying
  so) on the order page and the overview's quick view; paying asks cash or card
- a confirmed booking can keep its table ahead (manager, phones, counter):
  POST /api/connect/bookings/{id}/table, reservations create/PATCH; refused with
  reservation.table_kept within 2 h of another booking
- tests: test_manager_ordering.py, online bookings +2, manager orders.test.mjs,
  @xenia/ordering, e2e manager.mjs (take, change, pay-first close, RESERVED)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 21:58:46 +02:00
co-authored by Claude Opus 5.5
parent f4aae6abbc
commit 070c9cf625
56 changed files with 2339 additions and 3846 deletions
+23
View File
@@ -370,6 +370,29 @@ def arrive_booking(reservation_id: int, body: ArriveRequest, background: Backgro
return booking_out(r)
class KeepTableRequest(BaseModel):
table_id: Optional[int] = None
@router.post("/bookings/{reservation_id}/table")
def keep_table(reservation_id: int, body: KeepTableRequest, db: Session = Depends(get_db), user=Depends(_BOOKINGS)):
"""Give a confirmed booking its table ahead (plan step 6.9, from 4.8), or take it back (null).
The table then shows RESERVED when the booking is near (routers/tables) and the pickers say
it's kept; seating them later offers it first. One table can't be kept for two bookings
within two hours of each other."""
from services import online_reservations as svc
r = _booking(db, reservation_id)
if r.status != "pending":
raise XeniaError("reservation.status_changed", current=r.status)
svc.keep_table(db, r, body.table_id)
r.updated_at = utcnow()
db.commit()
db.refresh(r)
broadcast_sync("reservation_updated", {"reservation_id": r.id, "status": r.status, "table_id": r.table_id})
broadcast_sync("table_list_changed", {})
return booking_out(r)
@router.post("/bookings/{reservation_id}/cancel")
def cancel_booking(reservation_id: int, body: CancelRequest, background: BackgroundTasks,
db: Session = Depends(get_db), user=Depends(_BOOKINGS)):
+29
View File
@@ -327,6 +327,35 @@ def get_pending_prints(
return {"count": len(pending_jobs), "orders": orders_data}
@router.get("/menu")
def ordering_menu(db: Session = Depends(get_db), user: User = Depends(get_current_user)):
"""What the manager's ordering offers (plan step 6.9): the categories and every product sold
in the shop (eating in), with its in-store price now and its choices, in the counter's shape
(routers/pos._product_out), so the same product dialog and line ids (4.4) work; service items
(cover charge, cutlery…) too, marked `service`. Lines go to POST /{id}/items like the phones'."""
from sqlalchemy.orm import selectinload
from core import sales_points
from models.product import Category, ProductPreferenceSet
from routers.pos import _product_out
from services import pos_cart
if not (holds(user, "ordering.orders.open") or holds(user, "core.dashboard.access")):
raise XeniaError("access.denied", key="ordering.orders.open")
products = (db.query(Product)
.filter(Product.lifecycle_status == "active", Product.system_key.is_(None))
.options(selectinload(Product.quick_options), selectinload(Product.options), selectinload(Product.ingredients),
selectinload(Product.preference_sets).selectinload(ProductPreferenceSet.choices),
selectinload(Product.memberships))
.order_by(Product.sort_order, Product.name).all())
products = [p for p in products if p.is_service_item or sales_points.is_sold_at(p, "in_store")]
prices = pos_cart.unit_prices(db, products, "in_store") if products else []
cats = db.query(Category).order_by(Category.sort_order, Category.name).all()
return {
"categories": [{"id": c.id, "name": c.name, "color": c.color, "parent_id": c.parent_id, "sort_order": c.sort_order} for c in cats],
"products": [{**_product_out(p, prices[i]), "service": bool(p.is_service_item), "available": bool(p.is_available)}
for i, p in enumerate(products)],
}
@router.get("/{order_id}")
def get_order(order_id: int, db: Session = Depends(get_db), user: User = Depends(get_current_user)):
order = db.query(Order).filter(Order.id == order_id).first()
+15 -5
View File
@@ -47,15 +47,21 @@ def create_reservation(
email=body.email,
note=body.note,
reserved_for=body.reserved_for,
table_id=body.table_id,
source=body.source,
online_customer_id=body.online_customer_id,
created_by_user_id=user.id,
status="pending",
)
if body.table_id:
from services.online_reservations import keep_table
keep_table(db, r, body.table_id) # not kept for another booking close by (6.9)
db.add(r)
db.commit()
db.refresh(r)
from services.ws_bus import broadcast_sync
broadcast_sync("reservation_updated", {"reservation_id": r.id, "status": r.status, "table_id": r.table_id})
if r.table_id:
broadcast_sync("table_list_changed", {})
return _enrich(r)
@@ -123,10 +129,11 @@ def update_reservation(
raise XeniaError("reservation.not_found", reservation_id=reservation_id)
updates = body.model_dump(exclude_none=True)
if "table_id" in updates and updates["table_id"] is not None:
if not db.query(Table).filter(Table.id == updates["table_id"], Table.is_active == True).first():
raise XeniaError("table.not_found", status=400)
# the table: set, changed or taken back (null) — kept for one booking at a time (6.9)
if "table_id" in body.model_fields_set:
from services.online_reservations import keep_table
keep_table(db, r, body.table_id)
updates.pop("table_id", None)
if "status" in updates and updates["status"] not in VALID_STATUSES:
raise XeniaError("validation.choice", field='status', value=updates['status'])
@@ -137,6 +144,9 @@ def update_reservation(
r.updated_at = utcnow()
db.commit()
db.refresh(r)
from services.ws_bus import broadcast_sync
broadcast_sync("reservation_updated", {"reservation_id": r.id, "status": r.status, "table_id": r.table_id})
broadcast_sync("table_list_changed", {})
return _enrich(r)