feat(manager): products and categories on v2, a product in several categories, allergens (platform-v2 step 6.3)

- Management/ProductsTab + ProductFormModal (3.1k lines) → src/pages/products/: category tree,
  list/grid, toolbar + filters (search folds accents and Latin letters), bulk actions, category
  dialogs; the editor in editor/ (details, sold at, cost, fiscal; the waiter's choices).
  Arithmetic in productsLogic.js / editor/formLogic.js (tests/products.test.mjs).
- Several categories per product with a main one (D-23): edited in the editor, "also in" on the
  rows, each category's list ordered on its own (drag or up/down → PUT /reorder with category_id);
  bulk "move to" / "also list in". The waiter's picker now shows a product in every category.
- Allergens: products.allergens (Alembic 0032, core/allergens.py: 14 EU, contains | may_contain,
  catalog.allergen), in the API, POS menu, menu tablet, catalogue bundles and the cloud snapshot
  (C-2); @xenia/access allergens.js + <Allergens> shown on the phone, the counter, the tablet.
- Bell: only the newest load sets the list (an older answer could hide a live notification).
- e2e: manager (two categories, order per category, allergens), terminal / menu tablet / waiter
  (allergens shown); media saves by test id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 10:04:35 +02:00
co-authored by Claude Opus 5.5
parent 8a02173450
commit 5048f82a4c
53 changed files with 2812 additions and 3179 deletions
+5 -1
View File
@@ -1,6 +1,6 @@
from core.timeutil import venue_date, utcnow
import json
from core import sales_points
from core import allergens, sales_points
from datetime import datetime, timezone
from fastapi import APIRouter, Depends
from fastapi.responses import JSONResponse
@@ -60,6 +60,7 @@ def _serialize_product(p: Product) -> dict:
"name": p.name, "base_price": p.base_price, "is_available": p.is_available,
"lifecycle_status": p.lifecycle_status, "sort_order": p.sort_order,
"sold_at": sales_points.sold_at(p),
"allergens": allergens.of(p),
"quick_options": quick_options, "options": options,
"ingredients": ingredients, "preference_sets": preference_sets,
}
@@ -188,6 +189,8 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
existing.sort_order = prod_data.get("sort_order", 0)
if "sold_at" in prod_data: # phase 3S; older bundles: unchanged
existing.sold_at = sales_points.dump(prod_data["sold_at"])
if "allergens" in prod_data: # 6.3; older bundles: unchanged
existing.allergens = allergens.dump(prod_data["allergens"])
db.flush()
product = existing
else:
@@ -198,6 +201,7 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
lifecycle_status=prod_data.get("lifecycle_status", "active"),
sort_order=prod_data.get("sort_order", 0),
sold_at=sales_points.dump(prod_data.get("sold_at", sales_points.ALL)),
allergens=allergens.dump(prod_data.get("allergens")),
)
db.add(product)
db.flush()
+2 -1
View File
@@ -26,7 +26,7 @@ import time
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from core import sales_points
from core import allergens, sales_points
from core.access.deps import require_device
from core.errors import XeniaError
from database import get_db
@@ -124,6 +124,7 @@ def menu(db: Session = Depends(get_db), dev=Depends(require_device("menu_tablet"
"config": cfg,
"categories": out_cats,
"products": {str(p.id): {"id": p.id, "name": p.name, "description": p.description or None, "tags": _tags(p),
"allergens": allergens.of(p),
"price": round(prices[p.id], 2) if p.id in prices else None, "available": bool(p.is_available),
"image": media_store.image_of(p.media)} for p in shown},
}
+2 -1
View File
@@ -83,13 +83,14 @@ def _subs_out(raw):
def _product_out(p, price: float, prices: dict | None = None) -> dict:
shared = lambda ps: pos_cart._shared(ps.shared_subset) # noqa: E731
from core import sales_points
from core import allergens, sales_points
return {
"id": p.id, "name": p.name, "description": p.description, "image_url": p.image_url,
"price": round(price, 2), "prices": {k: round(v, 2) for k, v in (prices or {}).items()},
"sold_at": [sp for sp in sales_points.sold_at(p) if sp in sales_points.IN_PERSON],
"base_price": round(p.base_price, 2), "unit_type": p.unit_type or "piece",
"tags": _tags(p.tags),
"allergens": allergens.of(p),
"primary_category_id": p.primary_category_id,
"categories": [{"category_id": m.category_id, "sort_order": m.sort_order} for m in p.memberships],
"sort_order": p.sort_order,
+6 -3
View File
@@ -5,7 +5,7 @@ from pydantic import BaseModel
from sqlalchemy.orm import Session
from typing import List
from core import sales_points
from core import allergens, sales_points
from database import get_db
from models.product import Product, Category, ProductCategory, ProductOption, ProductQuickOption, ProductIngredient, ProductPreferenceSet, ProductPreferenceChoice, ProductModifierGroup
from models.prep_zone import PrepZone
@@ -369,12 +369,13 @@ def reorder_products(items: List[ProductReorderItem], db: Session = Depends(get_
@router.post("/", response_model=ProductOut, status_code=status.HTTP_201_CREATED)
def create_product(body: ProductCreate, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
data = body.model_dump(exclude={"quick_options", "options", "ingredients", "preference_sets", "cost_breakdown", "prep_zone_ids", "tags",
"category_id", "primary_category_id", "category_ids"})
"category_id", "primary_category_id", "category_ids", "allergens"})
if data.get("sort_order") == 0:
data["sort_order"] = db.query(Product).count()
if body.cost_breakdown is not None:
data["cost_breakdown"] = json.dumps([item.model_dump() for item in body.cost_breakdown])
data["tags"] = json.dumps(body.tags) if body.tags is not None else None
data["allergens"] = allergens.dump(body.allergens)
data["sold_at"] = sales_points.dump(body.sold_at)
data["media_id"] = _picture(db, body.media_id)
product = Product(**data)
@@ -432,7 +433,7 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
scalar_fields = body.model_dump(
exclude_none=True,
exclude={"quick_options", "options", "ingredients", "preference_sets", "cost_breakdown", "prep_zone_ids", "tags", "modifier_groups",
"category_id", "primary_category_id", "category_ids", "media_id"},
"category_id", "primary_category_id", "category_ids", "media_id", "allergens"},
)
if "media_id" in body.model_fields_set:
product.media_id = _picture(db, body.media_id)
@@ -454,6 +455,8 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
product.tags = json.dumps(body.tags)
elif "tags" in body.model_fields_set:
product.tags = None
if body.allergens is not None:
product.allergens = allergens.dump(body.allergens)
if body.quick_options is not None:
_replace_quick_options(db, product, body.quick_options)
# Modifier groups must be recreated before items so we have the ID map