feat: staff apps show the menu in the reader's language (plan 6R.L)
The waiters' phones and the counter show categories, products and every choice (quick options, extras and sub-choices, preferences, shared sets, ingredients, groups) in the signed-in person's language, falling back to the stored text. Display only: carts, lines, tickets and the kitchen keep the venue's text (ids, sub-choices by stored name). In the venue's own language nothing changes. - @xenia/access: menuText / useMenuText (mt, mt.choice, mt.line, mt.matches) - /api/pos/menu carries translations for products, categories and choices - shared ProductDialog takes a text() prop (the counter passes useMenuText) - search finds a product by its name in any language (counter, waiter) - waiter: useMenuNames for sent lines; picker, drawer, cart, summary, table lines, quantity / price history, favourites setup - counter: categories, cards, dialog, cart lines, table lines, payment rows - tests: access menuText, ordering search, test_pos per-language, e2e waiter.mjs and terminal.mjs 6R.L blocks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -76,16 +76,28 @@ def pos_session(db: Session = Depends(get_db), user=Depends(require(ACCESS))):
|
||||
|
||||
# ── menu ────────────────────────────────────────────────────────────────────
|
||||
|
||||
def _tr(x) -> dict:
|
||||
"""A choice's names per language {lang: text} (6R.L: the counter shows them in the cashier's
|
||||
language; display only, lines keep ids and the venue's names). A row or a sub-choice's dict."""
|
||||
from core.menu_languages import _load, names_of
|
||||
if isinstance(x, dict):
|
||||
return {k: v for k, v in _load(x.get("translations")).items() if isinstance(v, str)}
|
||||
return names_of(x)
|
||||
|
||||
|
||||
def _subs_out(raw):
|
||||
return [{"name": s["name"], "price": round(float(s.get("extra_cost") or 0.0), 2), "is_default": bool(s.get("is_default"))}
|
||||
return [{"name": s["name"], "price": round(float(s.get("extra_cost") or 0.0), 2), "is_default": bool(s.get("is_default")),
|
||||
"translations": _tr(s)}
|
||||
for s in pos_cart._subs(raw)]
|
||||
|
||||
|
||||
def _product_out(p, price: float, prices: dict | None = None) -> dict:
|
||||
shared = lambda ps: pos_cart._shared(ps.shared_subset) # noqa: E731
|
||||
from core import allergens, sales_points
|
||||
from core.menu_languages import of as product_tr
|
||||
return {
|
||||
"id": p.id, "name": p.name, "description": p.description, "image_url": p.image_url,
|
||||
"translations": product_tr(p), # 6R.L: {lang: {name, description}}; every choice below has its own
|
||||
"price": round(price, 2), "prices": {k: round(v, 2) for k, v in (prices or {}).items()},
|
||||
"sold_at": [sp for sp in sales_points.sold_at(p) if sp in sales_points.IN_PERSON],
|
||||
"base_price": round(p.base_price, 2), "unit_type": p.unit_type or "piece",
|
||||
@@ -95,18 +107,19 @@ def _product_out(p, price: float, prices: dict | None = None) -> dict:
|
||||
"primary_category_id": p.primary_category_id,
|
||||
"categories": [{"category_id": m.category_id, "sort_order": m.sort_order} for m in p.memberships],
|
||||
"sort_order": p.sort_order,
|
||||
"quick": [{"id": q.id, "name": q.name, "price": round(q.price or 0.0, 2), "allow_multiple": bool(q.allow_multiple)}
|
||||
"quick": [{"id": q.id, "name": q.name, "price": round(q.price or 0.0, 2), "allow_multiple": bool(q.allow_multiple),
|
||||
"translations": _tr(q)}
|
||||
for q in sorted(p.quick_options, key=lambda q: q.sort_order)],
|
||||
"options": [{"id": o.id, "name": o.name, "price": round(o.extra_cost or 0.0, 2), "allow_multiple": bool(o.allow_multiple),
|
||||
"multi_select": bool(o.multi_select), "subs": _subs_out(o.sub_choices)}
|
||||
"multi_select": bool(o.multi_select), "subs": _subs_out(o.sub_choices), "translations": _tr(o)}
|
||||
for o in p.options],
|
||||
"prefs": [{"id": ps.id, "name": ps.name, "default_choice_id": ps.default_choice_id, "multi": bool(ps.allow_multi_select),
|
||||
"shared": ({"name": shared(ps)["name"], "subs": _subs_out(shared(ps)["choices"])} if shared(ps) else None),
|
||||
"prefs": [{"id": ps.id, "name": ps.name, "translations": _tr(ps), "default_choice_id": ps.default_choice_id, "multi": bool(ps.allow_multi_select),
|
||||
"shared": ({"name": shared(ps)["name"], "translations": _tr(shared(ps)), "subs": _subs_out(shared(ps)["choices"])} if shared(ps) else None),
|
||||
"choices": [{"id": c.id, "name": c.name, "price": round(c.extra_cost or 0.0, 2),
|
||||
"disables_shared": bool(c.disables_subset), "subs": _subs_out(c.sub_choices)}
|
||||
"disables_shared": bool(c.disables_subset), "subs": _subs_out(c.sub_choices), "translations": _tr(c)}
|
||||
for c in ps.choices]}
|
||||
for ps in p.preference_sets],
|
||||
"ingredients": [{"id": i.id, "name": i.name} for i in p.ingredients],
|
||||
"ingredients": [{"id": i.id, "name": i.name, "translations": _tr(i)} for i in p.ingredients],
|
||||
}
|
||||
|
||||
|
||||
@@ -142,12 +155,14 @@ def pos_menu(request: Request, db: Session = Depends(get_db), user=Depends(requi
|
||||
default = pos_cart.point_for(settings["default_order_type"])
|
||||
cats = db.query(Category).order_by(Category.sort_order, Category.name).all()
|
||||
from services import price_changes, split_bills
|
||||
from core.menu_languages import of as product_tr
|
||||
return {
|
||||
# + the venue's switch for prices changed by hand (6F.3): 'off' hides the line discount
|
||||
"settings": {**settings, "price_change": price_changes.mode(db),
|
||||
# 6F.6: splitting a bill by amount (the level and the most equal parts)
|
||||
"split_amount": split_bills.level(db), "split_max_parts": split_bills.max_parts(db)},
|
||||
"categories": [{"id": c.id, "name": c.name, "color": c.color, "parent_id": c.parent_id, "sort_order": c.sort_order}
|
||||
"categories": [{"id": c.id, "name": c.name, "color": c.color, "parent_id": c.parent_id, "sort_order": c.sort_order,
|
||||
"translations": product_tr(c)}
|
||||
for c in cats],
|
||||
"products": [_product_out(p, by_point[default][i], {sp: by_point[sp][i] for sp in sales_points.IN_PERSON})
|
||||
for i, p in enumerate(products)],
|
||||
|
||||
Reference in New Issue
Block a user