05/05 Update API for iPad inspection follow-up
This commit is contained in:
+13
-1
@@ -65,6 +65,10 @@ def _inspection_payload(inspection):
|
|||||||
'completed_at': inspection.completed_at.isoformat()
|
'completed_at': inspection.completed_at.isoformat()
|
||||||
if inspection.completed_at else None,
|
if inspection.completed_at else None,
|
||||||
'mobile_local_id': inspection.mobile_local_id,
|
'mobile_local_id': inspection.mobile_local_id,
|
||||||
|
# ── Follow-up / re-inspection fields ──────────────────────────────
|
||||||
|
'follow_up_required': inspection.follow_up_required,
|
||||||
|
'follow_up_note': inspection.follow_up_note,
|
||||||
|
'parent_inspection_id': inspection.parent_inspection_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -214,6 +218,13 @@ def create_inspection():
|
|||||||
if status not in ('in_progress', 'completed'):
|
if status not in ('in_progress', 'completed'):
|
||||||
return api_error('status must be "in_progress" or "completed"', 400)
|
return api_error('status must be "in_progress" or "completed"', 400)
|
||||||
|
|
||||||
|
# ── Optional parent link (re-inspection) ──────────────────────────────
|
||||||
|
parent_inspection_id = data.get('parent_inspection_id')
|
||||||
|
if parent_inspection_id:
|
||||||
|
parent = db.session.get(Inspection, parent_inspection_id)
|
||||||
|
if parent is None:
|
||||||
|
return api_error('Parent inspection not found', 404)
|
||||||
|
|
||||||
# ── Score calculation ─────────────────────────────────────────────────
|
# ── Score calculation ─────────────────────────────────────────────────
|
||||||
overall_score = data.get('overall_score')
|
overall_score = data.get('overall_score')
|
||||||
if overall_score is None and status == 'completed':
|
if overall_score is None and status == 'completed':
|
||||||
@@ -242,6 +253,7 @@ def create_inspection():
|
|||||||
notes = json.dumps(notes_payload),
|
notes = json.dumps(notes_payload),
|
||||||
completed_at = completed_at if status == 'completed' else None,
|
completed_at = completed_at if status == 'completed' else None,
|
||||||
mobile_local_id = mobile_local_id,
|
mobile_local_id = mobile_local_id,
|
||||||
|
parent_inspection_id = parent_inspection_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
db.session.add(inspection)
|
db.session.add(inspection)
|
||||||
@@ -276,7 +288,7 @@ def create_inspection():
|
|||||||
log_action(ACTION_CREATE, 'Inspection', inspection.id,
|
log_action(ACTION_CREATE, 'Inspection', inspection.id,
|
||||||
f'{template.name} @ {facility.name}',
|
f'{template.name} @ {facility.name}',
|
||||||
f'source=mobile; status={status}; score={overall_score}; '
|
f'source=mobile; status={status}; score={overall_score}; '
|
||||||
f'local_id={mobile_local_id}')
|
f'local_id={mobile_local_id}; parent_id={parent_inspection_id}')
|
||||||
|
|
||||||
logger.info('API INSPECTIONS | created | inspection_id=%d | facility=%s | '
|
logger.info('API INSPECTIONS | created | inspection_id=%d | facility=%s | '
|
||||||
'template=%s | status=%s | score=%s | user=%s',
|
'template=%s | status=%s | score=%s | user=%s',
|
||||||
|
|||||||
Reference in New Issue
Block a user