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>
This commit is contained in:
@@ -90,6 +90,12 @@
|
||||
"print": {
|
||||
"failed_final": "Ένα δελτίο της παραγγελίας #{order_id} δεν τυπώθηκε ποτέ στον εκτυπωτή {printer} ({attempts} προσπάθειες).",
|
||||
"failing": "Ένα δελτίο της παραγγελίας #{order_id} δεν έχει τυπωθεί ακόμα στον εκτυπωτή {printer} (αποτυχημένες προσπάθειες μέχρι τώρα: {attempts}· συνεχίζει να προσπαθεί). Ελέγξτε τον εκτυπωτή."
|
||||
},
|
||||
"business_day": {
|
||||
"not_open": "Είναι {time} και η ημέρα δεν έχει ανοίξει.",
|
||||
"open_blocked": "Η ημέρα δεν άνοιξε μόνη της στις {time}: η άδεια δεν το επιτρέπει ({reason}).",
|
||||
"tables_open": "Είναι ώρα κλεισίματος ({time}) αλλά {count} παραγγελίες είναι ακόμα ανοιχτές. Η ημέρα κλείνει μόνη της μόλις κλείσουν.",
|
||||
"not_closed": "Η ημέρα έπρεπε να κλείσει στις {time} και είναι ακόμα ανοιχτή."
|
||||
}
|
||||
},
|
||||
"system_product": {
|
||||
|
||||
@@ -90,6 +90,12 @@
|
||||
"print": {
|
||||
"failed_final": "A ticket for order #{order_id} never printed on {printer} ({attempts} attempts).",
|
||||
"failing": "A ticket for order #{order_id} hasn't printed on {printer} yet (failed attempts so far: {attempts}; still retrying). Check the printer."
|
||||
},
|
||||
"business_day": {
|
||||
"not_open": "It's {time} and the day isn't open.",
|
||||
"open_blocked": "The day didn't open by itself at {time}: the license doesn't allow it ({reason}).",
|
||||
"tables_open": "It's closing time ({time}) but {count} orders are still open. The day closes by itself once they are closed.",
|
||||
"not_closed": "The day should have closed at {time} and is still open."
|
||||
}
|
||||
},
|
||||
"system_product": {
|
||||
|
||||
@@ -85,6 +85,7 @@ def notify(key: str, severity: str, audience: str, params: dict | None = None, *
|
||||
row = db.query(Notification).filter(
|
||||
Notification.dedupe_key == dedupe_key,
|
||||
(Notification.expires_at.is_(None)) | (Notification.expires_at > now),
|
||||
Notification.resolved_at.is_(None),
|
||||
).order_by(Notification.id.desc()).first()
|
||||
if row is not None:
|
||||
if not fold:
|
||||
@@ -119,6 +120,27 @@ def notify(key: str, severity: str, audience: str, params: dict | None = None, *
|
||||
db.close()
|
||||
|
||||
|
||||
def resolve(db, dedupe_keys) -> int:
|
||||
"""Sticky alerts whose cause is gone (6F.8): hide the live rows with these dedupe keys.
|
||||
Sends `platform_notification` {id, resolved: true} so open bells refresh. Commits."""
|
||||
from models.notification import Notification
|
||||
rows = db.query(Notification).filter(Notification.dedupe_key.in_(list(dedupe_keys)),
|
||||
Notification.resolved_at.is_(None)).all()
|
||||
if not rows:
|
||||
return 0
|
||||
now = utcnow()
|
||||
for r in rows:
|
||||
r.resolved_at = now
|
||||
db.commit()
|
||||
try:
|
||||
from services.ws_bus import broadcast_sync
|
||||
for r in rows:
|
||||
broadcast_sync(EVENT, {"id": r.id, "resolved": True}, user_ids=recipients(db, r.audience))
|
||||
except Exception:
|
||||
logger.exception("notification.resolve_event_failed")
|
||||
return len(rows)
|
||||
|
||||
|
||||
# ── producers that need a little logic ───────────────────────────────────────
|
||||
|
||||
EXPIRY_WARN_DAYS = (14, 7, 3, 1)
|
||||
|
||||
Reference in New Issue
Block a user