Files
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

45 lines
2.3 KiB
Python

"""Platform notifications (APPS_PLATFORM §10, plan step 1.11).
System messages to staff: license limits and expiry, support access used, print
failures (later: Ergani, close-day reminders). NOT staff chat or manager messages
(models/message.py, F-030), which stay separate.
- The text is an i18n key (`notification.<key>` in core/i18n/*.json) + params, rendered
in the reader's language when listed.
- audience: "all_managers" (holders of core.dashboard.access) | "perm:<key>" | "user:<id>".
- dedupe_key: while a row with the same key is still live (expires_at NULL or future, not
resolved), notify() bumps its `count` / `last_at` instead of adding a row.
- resolved_at (6F.8): a sticky alert ("the day isn't open") stays until its cause is gone;
core.notifications.resolve() then hides it.
Written through core/notifications.py only.
"""
from sqlalchemy import JSON, Column, ForeignKey, Integer, String
from core.timeutil import UTCDateTime, utcnow
from database import Base
class Notification(Base):
__tablename__ = "notifications"
__table_args__ = {"sqlite_autoincrement": True}
id = Column(Integer, primary_key=True, autoincrement=True)
key = Column(String, nullable=False, index=True) # e.g. "license.limit_reached"
severity = Column(String, nullable=False, default="info") # info | warning | critical
audience = Column(String, nullable=False, index=True)
params = Column(JSON, nullable=True)
dedupe_key = Column(String, nullable=True, index=True)
count = Column(Integer, nullable=False, default=1) # occurrences folded in by dedupe
created_at = Column(UTCDateTime, nullable=False, default=utcnow, index=True)
last_at = Column(UTCDateTime, nullable=False, default=utcnow)
expires_at = Column(UTCDateTime, nullable=True) # hidden (and dedupe ends) after this
resolved_at = Column(UTCDateTime, nullable=True) # 6F.8: a sticky alert whose cause is gone (hidden, dedupe ends)
class NotificationRead(Base):
__tablename__ = "notification_reads"
notification_id = Column(Integer, ForeignKey("notifications.id", ondelete="CASCADE"), primary_key=True)
user_id = Column(Integer, primary_key=True) # no FK: the support account (id 0) can read too
read_at = Column(UTCDateTime, nullable=False, default=utcnow)