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
+33 -1
View File
@@ -4,7 +4,7 @@ from typing import Optional, List, Any, Literal, Dict
from core.sales_points import ALL as _SALES_POINTS, sold_at as _sold_at
from core.allergens import of as _allergens_of
from core.menu_languages import of as _menu_tr_of, _load as _menu_tr
from core.menu_languages import of as _menu_tr_of, _load as _menu_tr, names_of as _choice_names
SalesPoint = Literal["in_store", "in_store_takeaway", "qr_table", "online_takeaway", "online_delivery", "online_preorder"]
@@ -76,6 +76,7 @@ class ModifierGroupCreate(BaseModel):
modifier_type: str # "option" | "ingredient" | "preference"
name: str
sort_order: int = 0
translations: Dict[str, str] = {} # its name per language (0042)
class ModifierGroupOut(BaseModel):
@@ -84,9 +85,15 @@ class ModifierGroupOut(BaseModel):
modifier_type: str
name: str
sort_order: int = 0
translations: Dict[str, str] = {} # its name per language (0042)
model_config = {"from_attributes": True}
@field_validator("translations", mode="before")
@classmethod
def _names(cls, v):
return {k: x for k, x in _menu_tr(v).items() if isinstance(x, str)}
# ── Quick Options ─────────────────────────────────────────────────────────────
@@ -98,6 +105,7 @@ class ProductQuickOptionCreate(BaseModel):
is_favorite: bool = False
favorite_sort_order: int = 0
is_compact: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
class ProductQuickOptionOut(BaseModel):
@@ -110,9 +118,15 @@ class ProductQuickOptionOut(BaseModel):
is_favorite: bool = False
favorite_sort_order: int = 0
is_compact: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
model_config = {"from_attributes": True}
@field_validator("translations", mode="before")
@classmethod
def _names(cls, v):
return {k: x for k, x in _menu_tr(v).items() if isinstance(x, str)}
# ── Options ──────────────────────────────────────────────────────────────────
@@ -124,6 +138,7 @@ class OptionSubChoice(BaseModel):
allow_multiple: bool = False
# When True renders as half-width card on the PWA
is_compact: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
class ProductOptionBase(BaseModel):
@@ -137,6 +152,7 @@ class ProductOptionBase(BaseModel):
# When True renders the option itself as half-width card on the PWA
is_compact: bool = False
group_id: Optional[int] = None
translations: Dict[str, str] = {} # its name per language (0042)
class ProductOptionCreate(ProductOptionBase):
@@ -168,6 +184,7 @@ class ProductOptionOut(ProductOptionBase):
'favorite_sort_order': getattr(data, 'favorite_sort_order', 0) or 0,
'is_compact': getattr(data, 'is_compact', False) or False,
'group_id': getattr(data, 'group_id', None),
'translations': _choice_names(data),
}
return data
@@ -182,6 +199,7 @@ class ProductIngredientBase(BaseModel):
# When True renders as half-width card on the PWA
is_compact: bool = False
group_id: Optional[int] = None
translations: Dict[str, str] = {} # its name per language (0042)
class ProductIngredientCreate(ProductIngredientBase):
@@ -194,6 +212,11 @@ class ProductIngredientOut(ProductIngredientBase):
model_config = {"from_attributes": True}
@field_validator("translations", mode="before")
@classmethod
def _names(cls, v):
return {k: x for k, x in _menu_tr(v).items() if isinstance(x, str)}
# ── Sub-choices (nested under a preference choice) ────────────────────────────
@@ -202,6 +225,7 @@ class SubChoice(BaseModel):
extra_cost: float = 0.0
is_default: bool = False
is_compact: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
# ── Shared subset (set-level, shown for all non-disabling choices) ─────────────
@@ -211,10 +235,12 @@ class SharedSubsetChoice(BaseModel):
extra_cost: float = 0.0
is_default: bool = False
is_compact: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
class SharedSubset(BaseModel):
name: str
translations: Dict[str, str] = {} # its name per language (0042)
choices: List[SharedSubsetChoice] = []
@@ -227,6 +253,7 @@ class PreferenceChoiceCreate(BaseModel):
disables_subset: bool = False
# When True renders as half-width card on the PWA
is_compact: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
class PreferenceChoiceOut(BaseModel):
@@ -237,6 +264,7 @@ class PreferenceChoiceOut(BaseModel):
sub_choices: List[SubChoice] = []
disables_subset: bool = False
is_compact: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
model_config = {"from_attributes": True}
@@ -260,6 +288,7 @@ class PreferenceChoiceOut(BaseModel):
'sub_choices': parsed,
'disables_subset': data.disables_subset or False,
'is_compact': getattr(data, 'is_compact', False) or False,
'translations': _choice_names(data),
}
return data
@@ -274,6 +303,7 @@ class PreferenceSetCreate(BaseModel):
group_id: Optional[int] = None
allow_multi_select: bool = False
allow_choice_quantity: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
class PreferenceSetOut(BaseModel):
@@ -288,6 +318,7 @@ class PreferenceSetOut(BaseModel):
group_id: Optional[int] = None
allow_multi_select: bool = False
allow_choice_quantity: bool = False
translations: Dict[str, str] = {} # its name per language (0042)
model_config = {"from_attributes": True}
@@ -315,6 +346,7 @@ class PreferenceSetOut(BaseModel):
'group_id': getattr(data, 'group_id', None),
'allow_multi_select': getattr(data, 'allow_multi_select', False) or False,
'allow_choice_quantity': getattr(data, 'allow_choice_quantity', False) or False,
'translations': _choice_names(data),
}
return data