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
+77
View File
@@ -0,0 +1,77 @@
"""Allergens per product (plan step 6.3): the 14 EU allergens, "contains" or "may contain",
set in the manager, carried to the counter, the phones, the menu tablet, the catalogue bundle
and the customer apps' menu (cloud contract C-2)."""
import re
from pathlib import Path
import pytest
from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures)
from tests.test_menu_tablet import menu, tablet # noqa: F401 (fixtures)
ROOT = Path(__file__).resolve().parents[2]
def test_set_change_and_clear(client, owner_h, menu):
pid = menu["souvlaki"].id
r = client.put(f"/api/products/{pid}", headers=owner_h,
json={"allergens": {"milk": "may_contain", "gluten": "contains"}})
assert r.status_code == 200, r.text
assert r.json()["allergens"] == {"gluten": "contains", "milk": "may_contain"} # the Annex's order
# other changes leave them alone
assert client.put(f"/api/products/{pid}", headers=owner_h, json={"base_price": 4}).json()["allergens"]["gluten"] == "contains"
assert client.put(f"/api/products/{pid}", headers=owner_h, json={"allergens": {}}).json()["allergens"] == {}
created = client.post("/api/products/", headers=owner_h, json={"name": "Salad", "base_price": 6, "allergens": {"celery": "contains"}})
assert created.status_code == 201 and created.json()["allergens"] == {"celery": "contains"}
plain = client.post("/api/products/", headers=owner_h, json={"name": "Water", "base_price": 1}).json()
assert plain["allergens"] == {}
@pytest.mark.parametrize("bad", [{"pollen": "contains"}, {"milk": "a_little"}])
def test_unknown_allergens_or_levels_are_refused(client, owner_h, menu, bad):
r = client.put(f"/api/products/{menu['beer'].id}", headers=owner_h, json={"allergens": bad})
assert r.status_code == 422 and err(r) == "catalog.allergen"
def test_they_reach_the_counter_the_phones_and_the_tablet(client, owner_h, menu, tablet, make_user, login):
pid = menu["steak"].id
client.put(f"/api/products/{pid}", headers=owner_h, json={"allergens": {"mustard": "contains"}})
waiter_h = login(make_user(role="waiter"), client="waiter")
phones = {p["id"]: p for p in client.get("/api/products/", headers=waiter_h).json()}
assert phones[pid]["allergens"] == {"mustard": "contains"}
data = client.get("/api/menu-tablet/menu", headers=tablet["h"]).json()
assert data["products"][str(pid)]["allergens"] == {"mustard": "contains"}
from routers.pos import _product_out
assert _product_out(menu["steak"], 12.0)["allergens"] == {"mustard": "contains"}
def test_catalogue_bundle_and_cloud_menu(client, db, owner_h, menu):
pid = menu["beer"].id
client.put(f"/api/products/{pid}", headers=owner_h, json={"allergens": {"gluten": "contains", "sulphites": "may_contain"}})
bundle = client.get("/api/data-transfer/export/catalog", headers=owner_h).json()
beer = next(p for c in bundle["data"]["categories"] for p in c["products"] if p["name"] == "Beer")
assert beer["allergens"] == {"gluten": "contains", "sulphites": "may_contain"}
client.put(f"/api/products/{pid}", headers=owner_h, json={"allergens": {}})
assert client.post("/api/data-transfer/import/catalog", headers=owner_h, json=bundle).status_code < 300
assert client.get("/api/products/?all=true", headers=owner_h).json()
db.expire_all()
from models.product import Product
from core.allergens import of
assert of(db.get(Product, pid)) == {"gluten": "contains", "sulphites": "may_contain"}
from services.cloud_sync import menu_snapshot
snap, _ = menu_snapshot(db)
products = {p["id"]: p for c in snap["categories"] for p in c["products"]}
assert products[pid]["allergens"] == {"gluten": "contains", "sulphites": "may_contain"}
def test_the_frontend_list_matches_the_backend():
"""packages/access/src/allergens.js keeps the same 14, in the same order."""
from core.allergens import ALLERGENS, LEVELS
js = (ROOT / "packages" / "access" / "src" / "allergens.js").read_text(encoding="utf-8")
listed = re.search(r"export const ALLERGENS = \[([^\]]*)\]", js).group(1)
assert [x.strip().strip("'") for x in listed.split(",") if x.strip()] == list(ALLERGENS)
levels = re.search(r"export const ALLERGEN_LEVELS = \[([^\]]*)\]", js).group(1)
assert [x.strip().strip("'") for x in levels.split(",") if x.strip()] == list(LEVELS)