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:
@@ -82,3 +82,71 @@ def test_the_frontend_list_matches_the_backend():
|
||||
js = (Path(__file__).resolve().parents[2] / "packages" / "access" / "src" / "menuLanguages.js").read_text(encoding="utf-8")
|
||||
listed = re.search(r"export const MENU_LANGUAGES = \[([^\]]*)\]", js).group(1)
|
||||
assert [x.strip().strip("'") for x in listed.split(",") if x.strip()] == list(MENU_LANGUAGES)
|
||||
|
||||
|
||||
def test_every_choice_keeps_its_names_per_language(client, db, owner_h, menu):
|
||||
"""Owner 2026-11-21 (0042): every choice has its name per language; empty ones dropped,
|
||||
unknown languages refused; sub-choices and the shared sub-set keep theirs in their JSON."""
|
||||
pid = menu["souvlaki"].id
|
||||
body = {
|
||||
"modifier_groups": [{"modifier_type": "ingredient", "name": "Sauces", "translations": {"el": "Σάλτσες", "en": "Sauces"}}],
|
||||
"quick_options": [{"name": "Πίτα", "translations": {"el": "Πίτα", "en": " Pitta ", "fr": ""}}],
|
||||
"ingredients": [{"name": "Κρεμμύδι", "group_id": 0, "translations": {"el": "Κρεμμύδι"}}],
|
||||
"options": [{"name": "Σιρόπι", "translations": {"en": "Syrup"}, "sub_choices": [{"name": "Καραμέλα", "translations": {"en": "Caramel", "el": ""}}]}],
|
||||
"preference_sets": [{"name": "Ζάχαρη", "translations": {"en": "Sugar"},
|
||||
"choices": [{"name": "Σκέτος", "translations": {"en": "No sugar"}, "sub_choices": [{"name": "Στέβια", "translations": {"en": "Stevia"}}]}],
|
||||
"shared_subset": {"name": "Γάλα", "translations": {"en": "Milk"}, "choices": [{"name": "Φρέσκο", "translations": {"en": "Fresh"}}]}}],
|
||||
}
|
||||
r = client.put(f"/api/products/{pid}", headers=owner_h, json=body)
|
||||
assert r.status_code == 200, r.text
|
||||
p = r.json()
|
||||
assert p["modifier_groups"][0]["translations"] == {"el": "Σάλτσες", "en": "Sauces"}
|
||||
assert p["quick_options"][0]["translations"] == {"el": "Πίτα", "en": "Pitta"}
|
||||
assert p["ingredients"][0]["translations"] == {"el": "Κρεμμύδι"}
|
||||
assert p["options"][0]["translations"] == {"en": "Syrup"}
|
||||
assert p["options"][0]["sub_choices"][0]["translations"] == {"en": "Caramel"}
|
||||
ps = p["preference_sets"][0]
|
||||
assert ps["translations"] == {"en": "Sugar"} and ps["choices"][0]["translations"] == {"en": "No sugar"}
|
||||
assert ps["choices"][0]["sub_choices"][0]["translations"] == {"en": "Stevia"}
|
||||
assert ps["shared_subset"]["translations"] == {"en": "Milk"} and ps["shared_subset"]["choices"][0]["translations"] == {"en": "Fresh"}
|
||||
bad = client.put(f"/api/products/{pid}", headers=owner_h, json={"quick_options": [{"name": "x", "translations": {"de": "x"}}]})
|
||||
assert bad.status_code == 422 and err(bad) == "catalog.translation"
|
||||
# the cloud's quick option names come from the option itself now
|
||||
from services.cloud_sync import menu_snapshot
|
||||
db.expire_all()
|
||||
snap, _ = menu_snapshot(db)
|
||||
souv = next(x for c in snap["categories"] for x in c["products"] if x["id"] == pid)
|
||||
assert souv["quick_options"][0]["names"] == {"el": "Πίτα", "en": "Pitta"}
|
||||
|
||||
|
||||
def test_migration_0042_puts_the_texts_in_their_language(tmp_path):
|
||||
"""0042: texts typed before had no language: Greek letters → el, else the venue's language;
|
||||
the product's old quick translations move onto the quick options."""
|
||||
import json
|
||||
from alembic import command
|
||||
from sqlalchemy import create_engine, text
|
||||
from core.schema import alembic_config, upgrade_to_head
|
||||
eng = create_engine(f"sqlite:///{(tmp_path / 'm.db').as_posix()}")
|
||||
with eng.begin() as conn:
|
||||
command.upgrade(alembic_config(conn), "0041_floor_item_color")
|
||||
conn.execute(text("insert into pos_settings (key, value, updated_at) values ('venue.language', 'el', '2026-01-01')"))
|
||||
conn.execute(text("insert into categories (id, name, sort_order, general_sort_order, auto_expanded) values (1, 'Ψητά', 0, 0, 0)"))
|
||||
conn.execute(text("insert into products (id, name, description, base_price, is_available, lifecycle_status, sort_order, sold_at, digital_available, "
|
||||
"unit_type, quick_add_enabled, is_service_item, translations) values (1, 'Burger', 'Με πατάτες', 8, 1, 'active', 0, '[]', 1, 'piece', 1, 0, "
|
||||
"'{\"en\": {\"description\": \"With fries\", \"quick\": {\"Μπέικον\": \"Bacon\"}}}')"))
|
||||
conn.execute(text("insert into product_quick_options (id, product_id, name, price, allow_multiple, sort_order, is_favorite, favorite_sort_order, is_compact) "
|
||||
"values (1, 1, 'Μπέικον', 1, 0, 0, 0, 0, 0)"))
|
||||
conn.execute(text("insert into product_options (id, product_id, name, extra_cost, allow_multiple, multi_select, is_favorite, favorite_sort_order, is_compact, sub_choices) "
|
||||
"values (1, 1, 'Σάλτσα', 0, 0, 0, 0, 0, 0, '[{\"name\": \"BBQ\"}]')"))
|
||||
upgrade_to_head(eng)
|
||||
with eng.connect() as conn:
|
||||
p = json.loads(conn.execute(text("select translations from products where id = 1")).scalar())
|
||||
q = json.loads(conn.execute(text("select translations from product_quick_options where id = 1")).scalar())
|
||||
o = conn.execute(text("select translations, sub_choices from product_options where id = 1")).fetchone()
|
||||
c = json.loads(conn.execute(text("select translations from categories where id = 1")).scalar())
|
||||
eng.dispose()
|
||||
# "Burger" has no Greek letters: the venue's language (el); the description is Greek; the English one is kept
|
||||
assert p == {"el": {"name": "Burger", "description": "Με πατάτες"}, "en": {"description": "With fries"}}
|
||||
assert q == {"el": "Μπέικον", "en": "Bacon"}
|
||||
assert json.loads(o[0]) == {"el": "Σάλτσα"} and json.loads(o[1])[0]["translations"] == {"el": "BBQ"}
|
||||
assert c == {"el": {"name": "Ψητά"}}
|
||||
|
||||
Reference in New Issue
Block a user