fix(meters): centralize alert investigation workflow
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
This commit is contained in:
parent
2213fffec3
commit
cfe702eeeb
2 changed files with 17 additions and 4 deletions
|
|
@ -258,6 +258,18 @@ def close_meter_alert(*, alert, conclusion, comment=None, user_id=None, commit=T
|
|||
return alert
|
||||
|
||||
|
||||
def investigate_meter_alert(*, alert, comment=None, user_id=None, commit=True):
|
||||
"""Passe une alerte ouverte en investigation via le service métier."""
|
||||
if alert.status not in {"OPEN", "INVESTIGATING"}:
|
||||
raise ValueError("Une alerte clôturée ne peut plus passer en investigation.")
|
||||
alert.status = "INVESTIGATING"
|
||||
if comment:
|
||||
alert.comment = comment
|
||||
if commit:
|
||||
db.session.commit()
|
||||
return alert
|
||||
|
||||
|
||||
def visible_open_meter_alerts(user):
|
||||
"""Retourne les alertes visibles dans Ma journée selon le RBAC métier."""
|
||||
query = MeterAlert.query.filter(MeterAlert.status.in_(("OPEN", "INVESTIGATING")))
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@ from ..core.services.meter_reading_planning import (
|
|||
create_round, ensure_occurrences_for_operational_date, generate_occurrences,
|
||||
record_occurrence_reading, record_occurrence_without_reading,
|
||||
)
|
||||
from ..core.services.meter_analytics import consumption_intervals, visible_open_meter_alerts, close_meter_alert
|
||||
from ..core.services.meter_analytics import (
|
||||
consumption_intervals, visible_open_meter_alerts, close_meter_alert,
|
||||
investigate_meter_alert,
|
||||
)
|
||||
from ..core.models.planning import MeterAlert, MeterAlertRule
|
||||
from .schedules import planning_bp
|
||||
|
||||
|
|
@ -224,9 +227,7 @@ def close_meter_alert_route(alert_id):
|
|||
alert = MeterAlert.query.get_or_404(alert_id)
|
||||
action = request.form.get('status', 'CLOSED').upper()
|
||||
if action == 'INVESTIGATING':
|
||||
alert.status = 'INVESTIGATING'
|
||||
alert.comment = request.form.get('comment') or alert.comment
|
||||
db.session.commit()
|
||||
investigate_meter_alert(alert=alert, comment=request.form.get('comment'), user_id=current_user.id)
|
||||
flash('Alerte passée en investigation.', 'success')
|
||||
else:
|
||||
try:
|
||||
|
|
|
|||
Loading…
Reference in a new issue