feat(backend): UTC time model - venue zone, business date, aware-only datetimes

Platform v2 step 1.1 (APPS_PLATFORM D-11, §7, D-24).
- core/timeutil.py: utcnow, venue_tz (venue.timezone, cached, invalidated on
  change - no restart), to_venue/venue_date/venue_strftime, parse_api_datetime
  (offset -> UTC; naive = venue-local; date = venue midnight), business_date_of
  /business_date_window (rollover hour, default 06:00), LocalClock + is_within,
  UTCDateTime column type (naive writes raise, reads are aware UTC), iso_z
- every model column is UTCDateTime; Pydantic UTCDatetime emits "...Z"
- business_days.business_date set at open; revision 0002 adds it (backfilled)
  and makes sync_events.created_at a UTCDateTime (AUTOINCREMENT restated)
- tz.py deleted; system.timezone setting replaced by venue.timezone (validated)
  + business_day.rollover_hour; manager timezone picker writes venue.timezone
- fixes: price-group schedules/time_range used the container's zone (happy
  hour bug); traffic report bucketed by UTC hour; reports' "date" meant the UTC
  calendar day, now the business date; reservations stored venue-local naive
  times (no-show check 2-3 h off) and listed by func.date; schedule week used
  UTC midnights; fiscal file names used container-local time
- seed.py/demo_seed.py create store_manager with role permissions (regression
  from step 1.0: v1's startup ALTER list used to rename/grant role 'manager')
- tzdata dependency; guard tests/guards/test_no_naive_time.py (AST scan);
  tests/test_timeutil.py covers the §7.3 DST cases and the API checks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 17:12:35 +02:00
co-authored by Claude Opus 5.5
parent d3d328804e
commit ab1e61a10f
66 changed files with 1122 additions and 437 deletions
+17 -3
View File
@@ -1,3 +1,5 @@
from core import timeutil
from core.timeutil import utcnow
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from datetime import datetime, timezone
@@ -22,7 +24,8 @@ 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",
"system.timezone": "IANA timezone name used by the backend container (e.g. Europe/Athens). Requires container restart to take effect.",
"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.",
"ui.table_colours": "JSON blob of table card colour scheme (light + dark modes) for the Waiter PWA.",
"dev.spoof_printing": "When enabled, all print jobs are silently dropped. Devices behave as if printing succeeded.",
@@ -79,7 +82,8 @@ DEFAULTS = {
"shifts.waiter_self_end": "true",
"shifts.hide_revenue_from_waiters": "false",
"business_day.force_close_allowed": "true",
"system.timezone": "Europe/Athens",
"venue.timezone": "Europe/Athens",
"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}}}',
"dev.spoof_printing": "false",
@@ -141,11 +145,19 @@ def update_setting(
):
if key not in VALID_SETTINGS:
raise HTTPException(status_code=400, detail=f"Unknown setting key: {key}")
if key == "venue.timezone":
try:
timeutil.validate_tz(body.value)
except ValueError:
raise HTTPException(status_code=422, detail=f"Unknown time zone: {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")
setting = db.query(PosSettings).filter(PosSettings.key == key).first()
if setting:
setting.value = body.value
setting.updated_at = datetime.now(timezone.utc)
setting.updated_at = utcnow()
setting.updated_by_id = user.id
else:
setting = PosSettings(key=key, value=body.value, updated_by_id=user.id)
@@ -153,4 +165,6 @@ def update_setting(
db.commit()
db.refresh(setting)
if key in ("venue.timezone", "business_day.rollover_hour"):
timeutil.invalidate() # live: next call re-reads the setting
return {"key": setting.key, "value": setting.value}