feat(menu): the menu in English and Greek (platform-v2 step 6.4, D-29)
- products.translations / categories.translations (Alembic 0033, core/menu_languages.py: el + en,
name / description / quick options by their base name; catalog.translation). Empty = the text
as typed; no machine translation (owner).
- In the manager's product editor ("In English" / "In Greek", quick extras), the category dialog,
and a menu board's Language (signage MenuContent.language).
- Customer screens only: cloud snapshot names / descriptions per language (C-2), the menu tablet's
EL / EN switch the names (localize), signage boards; tickets, KDS, counter, phones keep the base.
- Catalogue bundles carry translations; @xenia/access menuLanguages.js (a backend test compares).
- e2e: manager (the other language saved), menu tablet (EN / EL names), QR table (English on
the menu, the base name on the kitchen's order, Greek page as typed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from core.timeutil import venue_date, utcnow
|
||||
import json
|
||||
from core import allergens, sales_points
|
||||
from core import allergens, menu_languages, sales_points
|
||||
from datetime import datetime, timezone
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi.responses import JSONResponse
|
||||
@@ -61,6 +61,7 @@ def _serialize_product(p: Product) -> dict:
|
||||
"lifecycle_status": p.lifecycle_status, "sort_order": p.sort_order,
|
||||
"sold_at": sales_points.sold_at(p),
|
||||
"allergens": allergens.of(p),
|
||||
"translations": menu_languages.of(p),
|
||||
"quick_options": quick_options, "options": options,
|
||||
"ingredients": ingredients, "preference_sets": preference_sets,
|
||||
}
|
||||
@@ -77,6 +78,7 @@ def _serialize_category(cat: Category) -> dict:
|
||||
"name": cat.name, "color": cat.color, "sort_order": cat.sort_order,
|
||||
"parent_name": cat.parent.name if cat.parent else None,
|
||||
"general_sort_order": cat.general_sort_order, "auto_expanded": cat.auto_expanded,
|
||||
"translations": menu_languages.of(cat),
|
||||
"products": products,
|
||||
}
|
||||
|
||||
@@ -165,6 +167,8 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
|
||||
existing.sort_order = cat_data.get("sort_order", 0)
|
||||
existing.general_sort_order = cat_data.get("general_sort_order", 0)
|
||||
existing.auto_expanded = cat_data.get("auto_expanded", False)
|
||||
if "translations" in cat_data: # 6.4; older bundles: unchanged
|
||||
existing.translations = menu_languages.dump(menu_languages.normalize_category(cat_data["translations"]))
|
||||
db.flush()
|
||||
return existing
|
||||
else:
|
||||
@@ -175,6 +179,7 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
|
||||
parent_id=parent_id,
|
||||
general_sort_order=cat_data.get("general_sort_order", 0),
|
||||
auto_expanded=cat_data.get("auto_expanded", False),
|
||||
translations=menu_languages.dump(menu_languages.normalize_category(cat_data.get("translations"))),
|
||||
)
|
||||
db.add(cat)
|
||||
db.flush()
|
||||
@@ -191,6 +196,8 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
|
||||
existing.sold_at = sales_points.dump(prod_data["sold_at"])
|
||||
if "allergens" in prod_data: # 6.3; older bundles: unchanged
|
||||
existing.allergens = allergens.dump(prod_data["allergens"])
|
||||
if "translations" in prod_data: # 6.4
|
||||
existing.translations = menu_languages.dump(menu_languages.normalize_product(prod_data["translations"]))
|
||||
db.flush()
|
||||
product = existing
|
||||
else:
|
||||
@@ -202,6 +209,7 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
|
||||
sort_order=prod_data.get("sort_order", 0),
|
||||
sold_at=sales_points.dump(prod_data.get("sold_at", sales_points.ALL)),
|
||||
allergens=allergens.dump(prod_data.get("allergens")),
|
||||
translations=menu_languages.dump(menu_languages.normalize_product(prod_data.get("translations"))),
|
||||
)
|
||||
db.add(product)
|
||||
db.flush()
|
||||
|
||||
@@ -26,7 +26,7 @@ import time
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from core import allergens, sales_points
|
||||
from core import allergens, menu_languages, sales_points
|
||||
from core.access.deps import require_device
|
||||
from core.errors import XeniaError
|
||||
from database import get_db
|
||||
@@ -112,7 +112,8 @@ def menu(db: Session = Depends(get_db), dev=Depends(require_device("menu_tablet"
|
||||
ids = in_cat.get(c.id, [])
|
||||
has_sub = any(in_cat.get(x.id) for x in by_parent.get(c.id, []))
|
||||
if ids or has_sub:
|
||||
out_cats.append({"id": c.id, "name": c.name, "parent_id": c.parent_id, "depth": depth, "products": ids})
|
||||
out_cats.append({"id": c.id, "name": c.name, "names": menu_languages.texts(c.name, menu_languages.of(c), "name"),
|
||||
"parent_id": c.parent_id, "depth": depth, "products": ids})
|
||||
used.update(ids)
|
||||
shown = [by_id[i] for i in by_id if i in used]
|
||||
prices = dict(zip([p.id for p in shown], unit_prices(db, shown, point))) if point and shown else {}
|
||||
@@ -124,7 +125,7 @@ def menu(db: Session = Depends(get_db), dev=Depends(require_device("menu_tablet"
|
||||
"config": cfg,
|
||||
"categories": out_cats,
|
||||
"products": {str(p.id): {"id": p.id, "name": p.name, "description": p.description or None, "tags": _tags(p),
|
||||
"allergens": allergens.of(p),
|
||||
"allergens": allergens.of(p), **menu_languages.product_texts(p, customer=False),
|
||||
"price": round(prices[p.id], 2) if p.id in prices else None, "available": bool(p.is_available),
|
||||
"image": media_store.image_of(p.media)} for p in shown},
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ from pydantic import BaseModel
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
|
||||
from core import allergens, sales_points
|
||||
from core import allergens, menu_languages, sales_points
|
||||
from database import get_db
|
||||
from models.product import Product, Category, ProductCategory, ProductOption, ProductQuickOption, ProductIngredient, ProductPreferenceSet, ProductPreferenceChoice, ProductModifierGroup
|
||||
from models.prep_zone import PrepZone
|
||||
@@ -192,6 +192,7 @@ def create_category(body: CategoryCreate, db: Session = Depends(get_db), user: U
|
||||
parent_id=body.parent_id,
|
||||
general_sort_order=body.general_sort_order,
|
||||
media_id=_picture(db, body.media_id),
|
||||
translations=menu_languages.dump(menu_languages.normalize_category(body.translations)),
|
||||
)
|
||||
db.add(cat)
|
||||
db.commit()
|
||||
@@ -267,8 +268,10 @@ def update_category(category_id: int, body: CategoryUpdate, db: Session = Depend
|
||||
cat = db.query(Category).filter(Category.id == category_id).first()
|
||||
if not cat:
|
||||
raise XeniaError("catalog.category_not_found")
|
||||
for field, value in body.model_dump(exclude_none=True, exclude={"media_id"}).items():
|
||||
for field, value in body.model_dump(exclude_none=True, exclude={"media_id", "translations"}).items():
|
||||
setattr(cat, field, value)
|
||||
if body.translations is not None:
|
||||
cat.translations = menu_languages.dump(menu_languages.normalize_category(body.translations))
|
||||
if "media_id" in body.model_fields_set:
|
||||
cat.media_id = _picture(db, body.media_id)
|
||||
db.commit()
|
||||
@@ -369,13 +372,14 @@ def reorder_products(items: List[ProductReorderItem], db: Session = Depends(get_
|
||||
@router.post("/", response_model=ProductOut, status_code=status.HTTP_201_CREATED)
|
||||
def create_product(body: ProductCreate, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
|
||||
data = body.model_dump(exclude={"quick_options", "options", "ingredients", "preference_sets", "cost_breakdown", "prep_zone_ids", "tags",
|
||||
"category_id", "primary_category_id", "category_ids", "allergens"})
|
||||
"category_id", "primary_category_id", "category_ids", "allergens", "translations"})
|
||||
if data.get("sort_order") == 0:
|
||||
data["sort_order"] = db.query(Product).count()
|
||||
if body.cost_breakdown is not None:
|
||||
data["cost_breakdown"] = json.dumps([item.model_dump() for item in body.cost_breakdown])
|
||||
data["tags"] = json.dumps(body.tags) if body.tags is not None else None
|
||||
data["allergens"] = allergens.dump(body.allergens)
|
||||
data["translations"] = menu_languages.dump(menu_languages.normalize_product(body.translations))
|
||||
data["sold_at"] = sales_points.dump(body.sold_at)
|
||||
data["media_id"] = _picture(db, body.media_id)
|
||||
product = Product(**data)
|
||||
@@ -433,7 +437,7 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
|
||||
scalar_fields = body.model_dump(
|
||||
exclude_none=True,
|
||||
exclude={"quick_options", "options", "ingredients", "preference_sets", "cost_breakdown", "prep_zone_ids", "tags", "modifier_groups",
|
||||
"category_id", "primary_category_id", "category_ids", "media_id", "allergens"},
|
||||
"category_id", "primary_category_id", "category_ids", "media_id", "allergens", "translations"},
|
||||
)
|
||||
if "media_id" in body.model_fields_set:
|
||||
product.media_id = _picture(db, body.media_id)
|
||||
@@ -457,6 +461,8 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
|
||||
product.tags = None
|
||||
if body.allergens is not None:
|
||||
product.allergens = allergens.dump(body.allergens)
|
||||
if body.translations is not None:
|
||||
product.translations = menu_languages.dump(menu_languages.normalize_product(body.translations))
|
||||
if body.quick_options is not None:
|
||||
_replace_quick_options(db, product, body.quick_options)
|
||||
# Modifier groups must be recreated before items so we have the ID map
|
||||
|
||||
@@ -140,6 +140,7 @@ class MenuContent(_Strict):
|
||||
show_descriptions: bool = False
|
||||
badges: Dict[str, Badge] = Field(default_factory=dict) # product id → badge
|
||||
sold_out: Literal["strike", "hide"] = "strike"
|
||||
language: Optional[Literal["el", "en"]] = None # 6.4: the menu's language on this board; None = as typed
|
||||
# how it's laid out (the player pages through what doesn't fit, 5.5b)
|
||||
columns: int = Field(default=2, ge=1, le=3)
|
||||
page_size: Optional[int] = Field(default=None, ge=3, le=60) # items per page; None = as many as fit
|
||||
|
||||
Reference in New Issue
Block a user