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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user