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:
@@ -27,8 +27,10 @@ language). Translations add the other language:
|
||||
Quick options are kept by their base name (they are recreated on every product save, so ids
|
||||
change). A missing translation shows the base text, whatever its language — never Latin letters,
|
||||
never a machine translation (owner). Who sees translations: the customer-facing screens (QR menu,
|
||||
order app, menu tablet, signage menu boards). Tickets, the kitchen display, the counter and the
|
||||
waiters' phones keep the base text (the staff's).
|
||||
order app, menu tablet, signage menu boards), and since 6R.L the waiters' phones and the counter
|
||||
show menu names in the staff member's language, for display only (`@xenia/access` useMenuText;
|
||||
`routers/pos.py` sends every text per language). Order lines, tickets and the kitchen display keep
|
||||
the base text (the venue's): apps send ids, and sub-choices by their stored name.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
@@ -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)],
|
||||
|
||||
@@ -59,12 +59,40 @@ def test_menu_lists_what_a_cashier_sells(client, till, menu):
|
||||
burger = next(p for p in data["products"] if p["name"] == "Burger")
|
||||
assert burger["price"] == 10.0 and burger["description"] == "Beef, brioche" and burger["tags"] == ["spicy"]
|
||||
assert "cost_simple" not in burger and "cost_breakdown" not in burger
|
||||
assert burger["options"][0]["subs"][0] == {"name": "BBQ", "price": 0.2, "is_default": True}
|
||||
assert burger["options"][0]["subs"][0] == {"name": "BBQ", "price": 0.2, "is_default": True, "translations": {}}
|
||||
assert burger["prefs"][0]["shared"]["name"] == "Side" and burger["prefs"][0]["choices"][1]["disables_shared"] is True
|
||||
assert {c["name"] for c in data["categories"]} >= {"Food", "Drinks"}
|
||||
assert data["settings"]["default_order_type"] == "takeaway"
|
||||
|
||||
|
||||
def test_menu_carries_every_name_per_language_lines_keep_the_venues(client, db, till, menu, on_shift):
|
||||
"""6R.L: the counter gets each text per language to show in the cashier's language; what it
|
||||
sends is ids (and sub-choices by their stored name), so the order keeps the venue's text."""
|
||||
from models.order import OrderItem
|
||||
m = menu
|
||||
m["burger"].translations = json.dumps({"el": {"name": "Μπέργκερ", "description": "Μοσχάρι"}, "en": {"name": "Burger"}})
|
||||
m["food"].translations = json.dumps({"el": {"name": "Φαγητό"}})
|
||||
m["rare"].translations = json.dumps({"el": "Λίγο ψημένο"})
|
||||
m["cook"].translations = json.dumps({"el": "Ψήσιμο"})
|
||||
m["cook"].shared_subset = json.dumps({"name": "Side", "translations": {"el": "Συνοδευτικό"},
|
||||
"choices": [{"name": "Fries", "is_default": True, "translations": {"el": "Πατάτες"}},
|
||||
{"name": "Salad", "extra_cost": 1.0}]})
|
||||
db.commit()
|
||||
data = client.get("/api/pos/menu", headers=till["h"]).json()
|
||||
burger = next(p for p in data["products"] if p["id"] == m["burger"].id)
|
||||
assert burger["translations"]["el"] == {"name": "Μπέργκερ", "description": "Μοσχάρι"}
|
||||
pref = burger["prefs"][0]
|
||||
assert pref["translations"] == {"el": "Ψήσιμο"} and pref["shared"]["translations"] == {"el": "Συνοδευτικό"}
|
||||
assert pref["shared"]["subs"][0]["translations"] == {"el": "Πατάτες"} and pref["shared"]["subs"][1]["translations"] == {}
|
||||
assert next(c for c in pref["choices"] if c["id"] == m["rare"].id)["translations"] == {"el": "Λίγο ψημένο"}
|
||||
assert next(c for c in data["categories"] if c["id"] == m["food"].id)["translations"] == {"el": {"name": "Φαγητό"}}
|
||||
assert burger["quick"][0]["translations"] == {} and burger["ingredients"][0]["translations"] == {}
|
||||
r = sale(client, till, [burger_line(m)], [{"method": "cash"}], cash_given=20)
|
||||
assert r.status_code == 201, r.text
|
||||
item = db.query(OrderItem).filter(OrderItem.order_id == r.json()["order_id"]).one()
|
||||
assert [o["name"] for o in json.loads(item.selected_options)] == ["Rare", "Fries"] # the stored names, not a translation
|
||||
|
||||
|
||||
def test_quote_prices_on_the_server(client, till, menu):
|
||||
m = menu
|
||||
line = burger_line(m, quick=[{"id": m["burger"].quick_options[0].id, "qty": 2}],
|
||||
|
||||
Reference in New Issue
Block a user