feat(connect): the site side of online orders: fee line, customer's time, price check

Plan phase 3S, step S.5.
- Pull: an online order keeps the customer's time (orders.requested_for, None = as soon as
  possible) and delivery area; quick options are stored in the site's entry shape; items get
  their cost snapshot.
- The delivery fee is its own order line: a system product (products.system_key
  "delivery_fee", lifecycle "system", sold nowhere; services/system_products.py), created on
  first use in the venue's language with the VAT group most products use. Added printed and
  served, so kitchen tickets and the KDS never see it; paid at the counter with the items,
  counted in the shift, on the fiscal receipt with its VAT group. Never listed in the
  catalogue (products list, export, edit endpoints → 404) and never added by hand.
- Price check (services/online_check.py): each line priced as the snapshot prices it, at the
  order's time, and the fee through the same engine with the site's rules and the cloud's
  area id; differences kept on orders.online_price_diff and shown. The customer pays what
  the cloud charged.
- Counter: time chip (or as soon as possible), area, fee line, price warning; takeaway is
  its own kind (was shown as "at the venue") and finishes as "collected". KDS cards show the
  online reference and the time; kitchen tickets print the reference, the type and the time.
- Manager: Online ordering → "The fee on the receipt" (name, VAT group;
  PUT /api/connect/fees/fee-product, fees.vat_group_unknown); the online orders page shows
  the time, area and price warning.
- Migration 0019. Tests: tests/test_online_site_side.py (6), terminal unit test, e2e
  (terminal: fee, time, warning, paid in full; manager: fee line settings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 15:38:25 +02:00
co-authored by Claude Opus 5.5
parent 8ea44d71aa
commit 0ca700279a
38 changed files with 899 additions and 69 deletions
+10 -5
View File
@@ -271,7 +271,8 @@ def list_products(all: bool = False, category_id: int | None = None, sold_at: st
`sold_at` (comma-separated): only products sold at one of those sales points (phase 3S; the
waiter app asks for in_store,in_store_takeaway)."""
from sqlalchemy.orm import selectinload
q = db.query(Product).options(selectinload(Product.memberships), selectinload(Product.prep_zones))
q = (db.query(Product).filter(Product.system_key.is_(None)) # system products: never listed (S.5)
.options(selectinload(Product.memberships), selectinload(Product.prep_zones)))
has_dashboard = holds(user, "core.dashboard.access")
if not all or not has_dashboard:
# Waiters only see active, available products
@@ -395,7 +396,8 @@ def create_product(body: ProductCreate, db: Session = Depends(get_db), user: Use
@router.put("/{product_id}", response_model=ProductOut)
def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
product = db.query(Product).filter(Product.id == product_id).first()
# system products (the delivery fee line, S.5) are not part of the catalogue
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
scalar_fields = body.model_dump(
@@ -442,7 +444,8 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
@router.post("/{product_id}/image", response_model=ProductOut)
async def upload_product_image(product_id: int, file: UploadFile = File(...), db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
product = db.query(Product).filter(Product.id == product_id).first()
# system products (the delivery fee line, S.5) are not part of the catalogue
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
@@ -480,7 +483,8 @@ def list_modifier_groups(product_id: int, db: Session = Depends(get_db), user: U
@router.post("/{product_id}/modifier-groups", response_model=ModifierGroupOut, status_code=status.HTTP_201_CREATED)
def create_modifier_group(product_id: int, body: ModifierGroupCreate, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
product = db.query(Product).filter(Product.id == product_id).first()
# system products (the delivery fee line, S.5) are not part of the catalogue
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
g = ProductModifierGroup(product_id=product_id, modifier_type=body.modifier_type, name=body.name, sort_order=body.sort_order)
@@ -520,7 +524,8 @@ def delete_modifier_group(product_id: int, group_id: int, db: Session = Depends(
@router.delete("/{product_id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_product(product_id: int, hard: bool = False, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
product = db.query(Product).filter(Product.id == product_id).first()
# system products (the delivery fee line, S.5) are not part of the catalogue
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
if hard: