From 21f0641d8d2b5d763c528e4ed52b88766c40e5e2 Mon Sep 17 00:00:00 2001 From: Nguyen Ngo Date: Tue, 5 May 2026 18:13:15 -0400 Subject: [PATCH] 05/05 Fix API for iPad inspection follow-up issue --- app/api/inspections.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/api/inspections.py b/app/api/inspections.py index a9ca59a..9d4f3b5 100644 --- a/app/api/inspections.py +++ b/app/api/inspections.py @@ -259,6 +259,25 @@ def create_inspection(): db.session.add(inspection) db.session.flush() + # ── Auto-clear follow-up flag on parent ─────────────────────────────── + # When a completed re-inspection arrives that links to a parent, clear + # follow_up_required on the parent automatically. This mirrors the web + # list view's implicit logic (which hides the badge when follow_ups.any()) + # and ensures the History API response reflects the resolved state. + if parent_inspection_id and status == 'completed': + parent_insp = db.session.get(Inspection, parent_inspection_id) + if parent_insp and parent_insp.follow_up_required: + parent_insp.follow_up_required = False + logger.info( + 'API INSPECTIONS | follow_up cleared | parent_id=%d | ' + 'by_inspection_id=%d | user=%s', + parent_inspection_id, inspection.id, user.username, + ) + log_action(ACTION_UPDATE, 'Inspection', parent_inspection_id, + f'{parent_insp.template.name} @ {parent_insp.facility.name}', + f'follow_up_required=False (cleared by re-inspection ' + f'#{inspection.id} via mobile API)') + # ── Notifications ───────────────────────────────────────────────────── if status == 'completed': score_display = f'{overall_score:.1f}%' if overall_score is not None else 'N/A'