fix: reopen clears restored_at, wire settings, docs, startup warning

This commit is contained in:
Atharv1705
2026-11-12 17:34:04 +05:30
parent 5027c0766e
commit e2a6fa601e
17 changed files with 292 additions and 36 deletions
+28 -4
View File
@@ -17,7 +17,7 @@ from ..models import (
User,
Warranty,
)
from .calculations import alert_state
from .calculations import alert_state, compute_sla_status
from .permissions import Role
from .settings_service import get_setting_value
@@ -50,7 +50,13 @@ def _alert_settings(db: Session) -> dict[str, int]:
get_setting_value(db, "contract_expiry_alert_days", 30),
)
),
"calibration": int(get_setting_value(db, "calibration_lead_days", 15)),
"calibration": int(
get_setting_value(
db,
"calibration_due_window_days",
get_setting_value(db, "calibration_lead_days", 15),
)
),
"pm_in_house": int(get_setting_value(db, "pm_inhouse_lead_days", 15)),
"pm_outsourced": int(get_setting_value(db, "pm_outsourced_lead_days", 15)),
"insurance": int(
@@ -67,6 +73,13 @@ def _alert_settings(db: Session) -> dict[str, int]:
get_setting_value(db, "warranty_expiry_alert_days", 30),
)
),
"contract_red": int(
get_setting_value(
db,
"contract_critical_alert_days",
get_setting_value(db, "red_threshold_days", 7),
)
),
"red": int(get_setting_value(db, "red_threshold_days", 7)),
"critical_hours": int(
get_setting_value(
@@ -75,6 +88,8 @@ def _alert_settings(db: Session) -> dict[str, int]:
get_setting_value(db, "escalation_open_complaint_hours", 24),
)
),
"critical_sla_hours": int(get_setting_value(db, "critical_complaint_sla_hours", 4)),
"non_critical_sla_hours": int(get_setting_value(db, "non_critical_complaint_sla_hours", 24)),
}
@@ -130,7 +145,7 @@ def run_alert_check(db: Session) -> dict[str, object]:
.all()
)
for c in contracts:
state = alert_state(c.end_date, today, cfg["amc"], cfg["red"])
state = alert_state(c.end_date, today, cfg["amc"], cfg["contract_red"])
if state in ("yellow", "red"):
created += _add_if_new(
db,
@@ -273,7 +288,16 @@ def run_alert_check(db: Session) -> dict[str, object]:
threshold_secs = cfg["critical_hours"] * 3600
for c in crit_complaints:
elapsed = (_ensure_utc(eff_now) - _ensure_utc(c.registered_at)).total_seconds()
if elapsed >= threshold_secs:
sla_breached, _target_h = compute_sla_status(
c.priority,
c.registered_at,
c.attended_at,
c.restored_at,
critical_sla_hours=cfg["critical_sla_hours"],
non_critical_sla_hours=cfg["non_critical_sla_hours"],
now_utc=eff_now,
)
if elapsed >= threshold_secs or sla_breached:
created += _add_if_new(
db,
existing_keys,