05/05 Fix API for iPad inspection follow-up issue
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user