Files
xenia-pos-local/local_backend/models/business_day.py
T
bonaminandClaude Opus 5.5 096bd53dbd feat(backend,manager): the business day opens and closes by itself (opening hours, a time, or only an alert)
- services/day_auto.py: a minute loop (venue time, offline) opens the day when the opening
  hours start (or at business_day.auto_open_time) and closes it when they end (or at
  auto_close_time); 'alert' only tells the managers. Offsets before / after, one day across
  the break or one per span, spans past midnight belong to the day they start, a day closed
  by hand isn't reopened in the same span, a restart catches up the open (until the business
  date changes for 'time') and alerts a missed close instead of doing it late.
- The close runs only when no order of the day is unclosed (Q-10): otherwise a sticky alert
  and a new try every 15 minutes. A locked / expired license turns the open into an alert.
- Sticky notifications: notifications.resolved_at + core.notifications.resolve(); the
  alerts resolve when the day opens / closes (by hand or by itself).
- services/business_days.py: the one open / close path (the routes and the loop); days opened
  or closed by the system have no opener / closer and opened_auto / closed_auto (Alembic 0052).
- Manager: Settings -> Operation "Opening and closing the day"; the bell's action buttons
  ("Open now", "Go to the overview"); Reports -> Days marks days opened / closed by itself.

Plan platform-v2 6F.8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 13:17:15 +02:00

32 lines
1.6 KiB
Python

from sqlalchemy import Boolean, Column, Date, Integer, String, Float, ForeignKey, Text
from core.timeutil import UTCDateTime, utcnow
from sqlalchemy.orm import relationship
from database import Base
class BusinessDay(Base):
__tablename__ = "business_days"
id = Column(Integer, primary_key=True, index=True)
status = Column(String, default="open", nullable=False) # 'open' | 'closed'
opened_at = Column(UTCDateTime, default=utcnow, nullable=False)
# The date this day counts as (D-11): set once when the day opens with
# core.timeutil.business_date_of(opened_at), never recalculated. Reports group by it.
business_date = Column(Date, nullable=False, index=True)
opened_by_id = Column(Integer, ForeignKey("users.id"), nullable=True) # NULL = opened by the system (6F.8)
opened_auto = Column(Boolean, nullable=False, default=False) # 6F.8: opened / closed by
closed_auto = Column(Boolean, nullable=False, default=False) # services/day_auto.py
closed_at = Column(UTCDateTime, nullable=True)
closed_by_id = Column(Integer, ForeignKey("users.id"), nullable=True)
notes = Column(Text, nullable=True)
# Phase 2E — store-level cash reconciliation
store_opening_cash = Column(Float, nullable=True) # physical cash when day opens
store_closing_cash = Column(Float, nullable=True) # physical cash counted at close
store_cash_discrepancy = Column(Float, nullable=True) # store_closing - expected
opener = relationship("User", foreign_keys=[opened_by_id])
closer = relationship("User", foreign_keys=[closed_by_id])
shifts = relationship("WaiterShift", back_populates="business_day")