feat(backend): error codes, backend i18n (en/el) and language fields

Platform v2 step 1.2 (APPS_PLATFORM D-12, §3.2, §8).
- core/errors.py: XeniaError + CODES registry; handlers give every error the
  {"error": {code, params, message}, "detail"} shape: XeniaError, wrapped
  HTTPException (http.<status>, detail untouched), validation.invalid (FastAPI
  detail list kept), and internal.error 500 with the request id (body, header
  and log line)
- orders: the 18 "Order not found" raises -> XeniaError("order.not_found")
- core/i18n: t(key, lang, **params) with en/el JSON (en fallback), venue/zone/
  user language resolution, normalize_language; 56 print keys
- printer_service: every printed label goes through keys. Kitchen,
  cancellation and service-item tickets print in the prep zone's language
  (-> venue.language); reports/receipts/synopsis in venue.language. Greek
  output is unchanged. Print retries now pass the job's zone (language and
  item grouping were lost on retries)
- users.language, prep_zones.language (revision 0003), setting venue.language
  (default en); editable via PATCH /auth/me, staff update, prep zones API;
  "" = inherit
- tests: error shapes, key/placeholder parity, fallback, kitchen ticket per
  zone/venue language, language APIs; pack rule CS-12

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 17:29:31 +02:00
co-authored by Claude Opus 5.5
parent ab1e61a10f
commit 968b6c78fb
21 changed files with 901 additions and 115 deletions
+9 -2
View File
@@ -1,4 +1,5 @@
from core import timeutil
from core import i18n, timeutil
from core.errors import XeniaError
from core.timeutil import utcnow
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
@@ -24,6 +25,7 @@ VALID_SETTINGS = {
"shifts.waiter_self_end": "Allow waiters to end their own shifts without manager action",
"shifts.hide_revenue_from_waiters": "Hide ΕΙΣΠΡΑΞΗ and ΠΑΡΑΔ. ΠΟΣΟ stats from waiters in Shift Overview: 'true' | 'false'",
"business_day.force_close_allowed": "Allow force-closing business day with open tables",
"venue.language": "Default language (en | el) for staff without their own language, and for printed reports/receipts and tickets of zones without one.",
"venue.timezone": "IANA time zone of the venue (e.g. Europe/Athens). All times are shown in it; DST is automatic. Applies immediately.",
"business_day.rollover_hour": "Hour (0-23, venue time) before which a newly opened business day counts as the previous date. Default 6.",
"system.log_retention_days": "Days of daily backend log files to keep in data/logs (default 30). Applied at backend start.",
@@ -83,6 +85,7 @@ DEFAULTS = {
"shifts.hide_revenue_from_waiters": "false",
"business_day.force_close_allowed": "true",
"venue.timezone": "Europe/Athens",
"venue.language": "en",
"business_day.rollover_hour": "6",
"system.log_retention_days": "30",
"ui.table_colours": '{"light":{"free":{"cardBg":"#dde5ef","badgeBg":"rgba(255,255,255,0.92)","nameText":"#3d5270","badgeText":"#3d5270"},"mine":{"cardBg":"#e8610a","badgeBg":"rgba(255,255,255,0.92)","nameText":"#ffffff","badgeText":"#e8610a"},"open":{"cardBg":"#FF8F60","badgeBg":"rgba(255,255,255,0.92)","nameText":"#ffffff","badgeText":"#FF8F60"},"partially_paid":{"cardBg":"#FFDC67","badgeBg":"rgba(255,255,255,0.92)","nameText":"#ffffff","badgeText":"#d4a800"},"paid":{"cardBg":"#81D264","badgeBg":"rgba(255,255,255,0.92)","nameText":"#ffffff","badgeText":"#81D264"},"kds_ready":{"cardBg":"#22c55e","cardBg2":"#ffffff","badgeBg":"rgba(255,255,255,0.92)","badgeBg2":"rgba(255,255,255,0.92)","nameText":"#ffffff","nameText2":"#15803d","badgeText":"#15803d","badgeText2":"#22c55e","flash":true}},"dark":{"free":{"cardBg":"#243044","badgeBg":"rgba(255,255,255,0.92)","nameText":"#94b8d4","badgeText":"#94b8d4"},"mine":{"cardBg":"#e8610a","badgeBg":"rgba(255,255,255,0.92)","nameText":"#ffffff","badgeText":"#e8610a"},"open":{"cardBg":"#FF8F60","badgeBg":"rgba(255,255,255,0.92)","nameText":"#ffffff","badgeText":"#FF8F60"},"partially_paid":{"cardBg":"#FFDC67","badgeBg":"rgba(255,255,255,0.92)","nameText":"#ffffff","badgeText":"#d4a800"},"paid":{"cardBg":"#81D264","badgeBg":"rgba(255,255,255,0.92)","nameText":"#ffffff","badgeText":"#81D264"},"kds_ready":{"cardBg":"#16a34a","cardBg2":"#ffffff","badgeBg":"rgba(255,255,255,0.92)","badgeBg2":"rgba(255,255,255,0.92)","nameText":"#ffffff","nameText2":"#bbf7d0","badgeText":"#bbf7d0","badgeText2":"#16a34a","flash":true}}}',
@@ -149,7 +152,9 @@ def update_setting(
try:
timeutil.validate_tz(body.value)
except ValueError:
raise HTTPException(status_code=422, detail=f"Unknown time zone: {body.value}")
raise XeniaError("validation.unknown_timezone", timezone=body.value)
if key == "venue.language" and not i18n.is_supported(body.value):
raise XeniaError("validation.unknown_language", language=body.value)
if key == "business_day.rollover_hour":
if not (body.value.isdigit() and 0 <= int(body.value) <= 23):
raise HTTPException(status_code=422, detail="rollover_hour must be 0-23")
@@ -167,4 +172,6 @@ def update_setting(
db.refresh(setting)
if key in ("venue.timezone", "business_day.rollover_hour"):
timeutil.invalidate() # live: next call re-reads the setting
if key == "venue.language":
i18n.invalidate()
return {"key": setting.key, "value": setting.value}