06/19 Fix inspection doesn't send notification if flagging an issue
This commit is contained in:
+37
-8
@@ -393,17 +393,16 @@ def create_inspection():
|
||||
inspection_link = f'/inspections/{inspection.id}'
|
||||
|
||||
notify_by_matrix(
|
||||
event_type = 'inspection_completed',
|
||||
title = f'Inspection #{inspection.id} Completed (Mobile)',
|
||||
body = (
|
||||
f'{user.username} completed an inspection at '
|
||||
event_type = 'inspection_completed',
|
||||
title = f'Inspection #{inspection.id} Completed (Mobile)',
|
||||
body = (
|
||||
f'{user.display_name} completed an inspection at '
|
||||
f'{facility.name} using the "{template.name}" template. '
|
||||
f'Overall score: {score_display}.'
|
||||
),
|
||||
link = inspection_link,
|
||||
inspection_id = inspection.id,
|
||||
facility_id = facility_id,
|
||||
exclude_user_ids = {user.id},
|
||||
link = inspection_link,
|
||||
inspection_id = inspection.id,
|
||||
facility_id = facility_id,
|
||||
)
|
||||
|
||||
db.session.commit()
|
||||
@@ -477,6 +476,8 @@ def update_inspection(inspection_id):
|
||||
existing_notes['_inspector_notes'] = data['notes']
|
||||
inspection.notes = json.dumps(existing_notes)
|
||||
|
||||
prev_status = inspection.status
|
||||
|
||||
if 'status' in data:
|
||||
inspection.status = data['status']
|
||||
|
||||
@@ -492,6 +493,34 @@ def update_inspection(inspection_id):
|
||||
elif data.get('status') == 'completed' and not inspection.completed_at:
|
||||
inspection.completed_at = now_eastern()
|
||||
|
||||
# Notify when a draft transitions to completed (mirrors the POST handler and web route).
|
||||
transitioning_to_complete = (
|
||||
data.get('status') == 'completed' and prev_status != 'completed'
|
||||
)
|
||||
if transitioning_to_complete:
|
||||
score_val = inspection.overall_score
|
||||
score_display = f'{score_val:.1f}%' if score_val is not None else 'N/A'
|
||||
template_name = inspection.template.name if inspection.template else 'Unknown'
|
||||
facility_name = inspection.facility.name if inspection.facility else 'Unknown'
|
||||
try:
|
||||
from flask import url_for
|
||||
inspection_link = url_for('inspections.view',
|
||||
inspection_id=inspection.id, _external=False)
|
||||
except RuntimeError:
|
||||
inspection_link = f'/inspections/{inspection.id}'
|
||||
notify_by_matrix(
|
||||
event_type = 'inspection_completed',
|
||||
title = f'Inspection #{inspection.id} Completed (Mobile)',
|
||||
body = (
|
||||
f'{user.display_name} completed an inspection at '
|
||||
f'{facility_name} using the "{template_name}" template. '
|
||||
f'Overall score: {score_display}.'
|
||||
),
|
||||
link = inspection_link,
|
||||
inspection_id = inspection.id,
|
||||
facility_id = inspection.facility_id,
|
||||
)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
log_action(ACTION_UPDATE, 'Inspection', inspection.id,
|
||||
|
||||
Reference in New Issue
Block a user