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