feat(products): every menu text per language, the editor's language picker, service item dialog

- Alembic 0042: a `translations` column on every choice (groups, quick options,
  extras, ingredients, preference sets and choices; sub-choices and shared
  sub-sets in their JSON); the texts typed so far become the text in their
  language (Greek letters → el, else the venue's); the product's old quick map
  moves onto the quick options. API, catalogue bundle and the cloud's quick
  option names carry them; names are checked before anything is replaced.
- Editor: a language picker beside the close button (Default = the venue's
  language, plus every menu language) drives every name and description, left
  and right; an empty language shows what is used instead as its placeholder.
  The shown name is the venue language's, else any (never mixed).
- Choices: one name field; the shared controls at one height (heart red when on,
  several / compact… chips coloured when on, delete red on hover); "+ Preference"
  at the right end of the tab strip; preference groups made inside a preference.
- Categories: the shared dropdown to add one; the category dialog per language.
- The service item switch is gone: "New service item" opens its own small dialog.
- UI: Dialog headerEnd; a toned toggle keeps its colour while pressed.
- Tests: backend (choice names, migration 0042), access, editor logic, e2e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 18:21:50 +02:00
co-authored by Claude Opus 5.5
parent 301502965c
commit 15413dea1b
30 changed files with 853 additions and 313 deletions
+23 -9
View File
@@ -22,11 +22,17 @@ EXPORT_VERSION = 1 # tables bundle
CATALOG_EXPORT_VERSION = 2 # catalogue bundle: v2 = products listed in several categories (D-23)
def _names(value):
"""A choice's names per language from a bundle (0042), stored cleaned."""
return menu_languages.dump(menu_languages.normalize_names(value))
def _serialize_product(p: Product) -> dict:
quick_options = [
{"name": qo.name, "price": qo.price, "allow_multiple": qo.allow_multiple,
"sort_order": qo.sort_order, "is_favorite": qo.is_favorite,
"favorite_sort_order": qo.favorite_sort_order, "is_compact": qo.is_compact}
"favorite_sort_order": qo.favorite_sort_order, "is_compact": qo.is_compact,
"translations": menu_languages.names_of(qo)}
for qo in p.quick_options
]
options = []
@@ -34,10 +40,12 @@ def _serialize_product(p: Product) -> dict:
sub = json.loads(opt.sub_choices) if opt.sub_choices else []
options.append({"name": opt.name, "extra_cost": opt.extra_cost,
"allow_multiple": opt.allow_multiple, "sub_choices": sub,
"is_favorite": opt.is_favorite, "favorite_sort_order": opt.favorite_sort_order})
"is_favorite": opt.is_favorite, "favorite_sort_order": opt.favorite_sort_order,
"translations": menu_languages.names_of(opt)})
ingredients = [
{"name": ing.name, "extra_cost": ing.extra_cost,
"is_favorite": ing.is_favorite, "favorite_sort_order": ing.favorite_sort_order}
"is_favorite": ing.is_favorite, "favorite_sort_order": ing.favorite_sort_order,
"translations": menu_languages.names_of(ing)}
for ing in p.ingredients
]
preference_sets = []
@@ -50,11 +58,13 @@ def _serialize_product(p: Product) -> dict:
default_index = i
sub = json.loads(ch.sub_choices) if ch.sub_choices else []
choices.append({"name": ch.name, "extra_cost": ch.extra_cost,
"sub_choices": sub, "disables_subset": ch.disables_subset})
"sub_choices": sub, "disables_subset": ch.disables_subset,
"translations": menu_languages.names_of(ch)})
preference_sets.append({
"name": ps.name, "choices": choices,
"default_choice_index": default_index, "shared_subset": shared,
"is_favorite": ps.is_favorite, "favorite_sort_order": ps.favorite_sort_order,
"translations": menu_languages.names_of(ps),
})
return {
"name": p.name, "base_price": p.base_price, "is_available": p.is_available,
@@ -226,7 +236,9 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
db.flush()
for qo in prod_data.get("quick_options", []):
db.add(ProductQuickOption(product_id=product.id, **qo))
qo = dict(qo)
names = _names(qo.pop("translations", None))
db.add(ProductQuickOption(product_id=product.id, **qo, translations=names))
for opt in prod_data.get("options", []):
sub_json = json.dumps(opt.get("sub_choices", []))
@@ -234,11 +246,13 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
product_id=product.id, name=opt["name"], extra_cost=opt.get("extra_cost", 0.0),
allow_multiple=opt.get("allow_multiple", False), sub_choices=sub_json,
is_favorite=opt.get("is_favorite", False),
favorite_sort_order=opt.get("favorite_sort_order", 0),
favorite_sort_order=opt.get("favorite_sort_order", 0), translations=_names(opt.get("translations")),
))
for ing in prod_data.get("ingredients", []):
db.add(ProductIngredient(product_id=product.id, **ing))
ing = dict(ing)
names = _names(ing.pop("translations", None))
db.add(ProductIngredient(product_id=product.id, **ing, translations=names))
for ps_data in prod_data.get("preference_sets", []):
shared_json = json.dumps(ps_data["shared_subset"]) if ps_data.get("shared_subset") else None
@@ -246,7 +260,7 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
product_id=product.id, name=ps_data["name"],
shared_subset=shared_json,
is_favorite=ps_data.get("is_favorite", False),
favorite_sort_order=ps_data.get("favorite_sort_order", 0),
favorite_sort_order=ps_data.get("favorite_sort_order", 0), translations=_names(ps_data.get("translations")),
)
db.add(ps)
db.flush()
@@ -255,7 +269,7 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
sub_json = json.dumps(ch.get("sub_choices", []))
choice = ProductPreferenceChoice(
set_id=ps.id, name=ch["name"], extra_cost=ch.get("extra_cost", 0.0),
sub_choices=sub_json, disables_subset=ch.get("disables_subset", False),
sub_choices=sub_json, disables_subset=ch.get("disables_subset", False), translations=_names(ch.get("translations")),
)
db.add(choice)
db.flush()
+48 -7
View File
@@ -26,6 +26,35 @@ from core.errors import XeniaError
router = APIRouter()
def _sub_dump(sub) -> dict:
"""A sub-choice (or a shared sub-set) as stored: its names per language cleaned (0042)."""
d = sub.model_dump()
d["translations"] = menu_languages.normalize_names(d.get("translations"))
if "choices" in d:
d["choices"] = [_sub_dump(c) for c in sub.choices]
return d
def _check_names(body) -> None:
"""Every choice's names valid before anything is replaced (a refusal changes nothing)."""
subs = lambda xs: [menu_languages.normalize_names(x.translations) for x in xs or []] # noqa: E731
for g in body.modifier_groups or []:
menu_languages.normalize_names(g.translations)
for x in [*(body.quick_options or []), *(body.ingredients or [])]:
menu_languages.normalize_names(x.translations)
for o in body.options or []:
menu_languages.normalize_names(o.translations)
subs(o.sub_choices)
for ps in body.preference_sets or []:
menu_languages.normalize_names(ps.translations)
for c in ps.choices:
menu_languages.normalize_names(c.translations)
subs(c.sub_choices)
if ps.shared_subset:
menu_languages.normalize_names(ps.shared_subset.translations)
subs(ps.shared_subset.choices)
def _broadcast_products_changed():
broadcast_sync("products_changed", {})
@@ -43,6 +72,7 @@ def _replace_modifier_groups(db, product, groups):
modifier_type=g.modifier_type,
name=g.name,
sort_order=i,
translations=menu_languages.dump(menu_languages.normalize_names(g.translations)),
)
db.add(new_g)
db.flush()
@@ -64,6 +94,7 @@ def _replace_quick_options(db, product, quick_options):
is_favorite=qo.is_favorite,
favorite_sort_order=qo.favorite_sort_order,
is_compact=qo.is_compact,
translations=menu_languages.dump(menu_languages.normalize_names(qo.translations)),
))
@@ -72,7 +103,7 @@ def _replace_options(db, product, options, group_id_map=None):
db.delete(opt)
db.flush()
for opt in options:
sub_json = json.dumps([s.model_dump() for s in opt.sub_choices]) if opt.sub_choices else None
sub_json = json.dumps([_sub_dump(s) for s in opt.sub_choices], ensure_ascii=False) if opt.sub_choices else None
resolved_group = group_id_map[opt.group_id] if (group_id_map and opt.group_id is not None and opt.group_id < len(group_id_map)) else None
db.add(ProductOption(
product_id=product.id,
@@ -85,6 +116,7 @@ def _replace_options(db, product, options, group_id_map=None):
favorite_sort_order=opt.favorite_sort_order,
is_compact=opt.is_compact,
group_id=resolved_group,
translations=menu_languages.dump(menu_languages.normalize_names(opt.translations)),
))
@@ -94,7 +126,8 @@ def _replace_ingredients(db, product, ingredients, group_id_map=None):
db.flush()
for ing in ingredients:
resolved_group = group_id_map[ing.group_id] if (group_id_map and ing.group_id is not None and ing.group_id < len(group_id_map)) else None
db.add(ProductIngredient(product_id=product.id, **ing.model_dump(exclude={'group_id'}), group_id=resolved_group))
db.add(ProductIngredient(product_id=product.id, **ing.model_dump(exclude={'group_id', 'translations'}), group_id=resolved_group,
translations=menu_languages.dump(menu_languages.normalize_names(ing.translations))))
def _replace_preference_sets(db, product, sets: List[PreferenceSetCreate], group_id_map=None):
@@ -102,7 +135,7 @@ def _replace_preference_sets(db, product, sets: List[PreferenceSetCreate], group
db.delete(ps)
db.flush()
for ps in sets:
shared_json = json.dumps(ps.shared_subset.model_dump()) if ps.shared_subset else None
shared_json = json.dumps(_sub_dump(ps.shared_subset), ensure_ascii=False) if ps.shared_subset else None
resolved_group = group_id_map[ps.group_id] if (group_id_map and ps.group_id is not None and ps.group_id < len(group_id_map)) else None
new_set = ProductPreferenceSet(
product_id=product.id,
@@ -113,12 +146,13 @@ def _replace_preference_sets(db, product, sets: List[PreferenceSetCreate], group
group_id=resolved_group,
allow_multi_select=ps.allow_multi_select,
allow_choice_quantity=ps.allow_choice_quantity,
translations=menu_languages.dump(menu_languages.normalize_names(ps.translations)),
)
db.add(new_set)
db.flush()
created_choices = []
for ch in ps.choices:
sub_json = json.dumps([s.model_dump() for s in ch.sub_choices]) if ch.sub_choices else None
sub_json = json.dumps([_sub_dump(s) for s in ch.sub_choices], ensure_ascii=False) if ch.sub_choices else None
choice = ProductPreferenceChoice(
set_id=new_set.id,
name=ch.name,
@@ -126,6 +160,7 @@ def _replace_preference_sets(db, product, sets: List[PreferenceSetCreate], group
sub_choices=sub_json,
disables_subset=ch.disables_subset,
is_compact=ch.is_compact,
translations=menu_languages.dump(menu_languages.normalize_names(ch.translations)),
)
db.add(choice)
db.flush()
@@ -371,6 +406,7 @@ 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)):
_check_names(body)
data = body.model_dump(exclude={"quick_options", "options", "ingredients", "preference_sets", "cost_breakdown", "prep_zone_ids", "tags",
"category_id", "primary_category_id", "category_ids", "allergens", "translations"})
if data.get("sort_order") == 0:
@@ -400,11 +436,12 @@ def create_product(body: ProductCreate, db: Session = Depends(get_db), user: Use
is_favorite=qo.is_favorite,
favorite_sort_order=qo.favorite_sort_order,
is_compact=qo.is_compact,
translations=menu_languages.dump(menu_languages.normalize_names(qo.translations)),
))
created_groups = _replace_modifier_groups(db, product, body.modifier_groups)
group_id_map = [g.id for g in created_groups]
for opt in body.options:
sub_json = json.dumps([s.model_dump() for s in opt.sub_choices]) if opt.sub_choices else None
sub_json = json.dumps([_sub_dump(s) for s in opt.sub_choices], ensure_ascii=False) if opt.sub_choices else None
resolved_group = group_id_map[opt.group_id] if (opt.group_id is not None and opt.group_id < len(group_id_map)) else None
db.add(ProductOption(
product_id=product.id,
@@ -417,10 +454,12 @@ def create_product(body: ProductCreate, db: Session = Depends(get_db), user: Use
favorite_sort_order=opt.favorite_sort_order,
is_compact=opt.is_compact,
group_id=resolved_group,
translations=menu_languages.dump(menu_languages.normalize_names(opt.translations)),
))
for ing in body.ingredients:
resolved_group = group_id_map[ing.group_id] if (ing.group_id is not None and ing.group_id < len(group_id_map)) else None
db.add(ProductIngredient(product_id=product.id, **ing.model_dump(exclude={'group_id'}), group_id=resolved_group))
db.add(ProductIngredient(product_id=product.id, **ing.model_dump(exclude={'group_id', 'translations'}), group_id=resolved_group,
translations=menu_languages.dump(menu_languages.normalize_names(ing.translations))))
_replace_preference_sets(db, product, body.preference_sets, group_id_map)
db.commit()
db.refresh(product)
@@ -434,6 +473,7 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise XeniaError("product.not_found")
_check_names(body)
scalar_fields = body.model_dump(
exclude_none=True,
exclude={"quick_options", "options", "ingredients", "preference_sets", "cost_breakdown", "prep_zone_ids", "tags", "modifier_groups",
@@ -495,7 +535,8 @@ def create_modifier_group(product_id: int, body: ModifierGroupCreate, db: Sessio
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise XeniaError("product.not_found")
g = ProductModifierGroup(product_id=product_id, modifier_type=body.modifier_type, name=body.name, sort_order=body.sort_order)
g = ProductModifierGroup(product_id=product_id, modifier_type=body.modifier_type, name=body.name, sort_order=body.sort_order,
translations=menu_languages.dump(menu_languages.normalize_names(body.translations)))
db.add(g)
db.commit()
db.refresh(g)