Aug 25 - Implement new function allow Director (internal & customer) to assign and inspection to another inspector

This commit is contained in:
2026-08-25 12:24:34 -04:00
parent b31f5f03da
commit aced3d0602
6 changed files with 286 additions and 8 deletions
+31 -3
View File
@@ -210,6 +210,11 @@ def _inspection_payload(inspection):
# ── Follow-up / re-inspection fields ──────────────────────────────
'follow_up_required': inspection.follow_up_required,
'follow_up_note': inspection.follow_up_note,
# phase53 — who is to perform the follow-up. NULL means the
# inspection's own inspector, which is what it always meant.
'follow_up_assigned_to': inspection.follow_up_assigned_to,
'follow_up_assigned_to_name': (inspection.follow_up_assignee.display_name
if inspection.follow_up_assignee else None),
'parent_inspection_id': inspection.parent_inspection_id,
# Set when this inspection was started from a ScheduledInspection —
# drives the "Scheduled" badge on the web list and lets the iPad show
@@ -267,8 +272,15 @@ def list_inspections():
query = Inspection.query
# Inspectors only see their own inspections
if user.is_inspector:
# Inspectors only see their own inspections.
#
# EXCEPT when asking for follow-up requests: a follow-up can now be handed
# to a different inspector (phase53), and that request lives on an
# inspection somebody ELSE performed. Applying this filter first would hide
# exactly the rows the assignee needs, so it is deferred to the follow-up
# block below, which applies ownership instead of authorship.
wants_follow_ups = request.args.get('follow_up_required', '').lower() in ('true', '1')
if user.is_inspector and not wants_follow_ups:
query = query.filter(Inspection.inspector_id == user.id)
# Optional filters
@@ -280,7 +292,7 @@ def list_inspections():
if status:
query = query.filter(Inspection.status == status)
if request.args.get('follow_up_required', '').lower() in ('true', '1'):
if wants_follow_ups:
# Must mean exactly what "Follow-up" means everywhere on the web
# (inspections.list / reports status_filter == 'follow_up'): flagged,
# completed, and not yet answered by a linked re-inspection.
@@ -298,6 +310,22 @@ def list_inspections():
Inspection.status == 'completed',
).filter(~Inspection.follow_ups.any())
# Ownership, not authorship (phase53). Mirrors
# Inspection.follow_up_owner: an assigned follow-up belongs to the
# assignee ALONE, an unassigned one to the inspection's own inspector.
#
# The two arms are mutually exclusive on purpose. Without the second
# arm's `is_(None)` an inspector would keep seeing a follow-up that had
# been handed to someone else, and two people would turn up to do it.
if user.is_inspector:
query = query.filter(db.or_(
Inspection.follow_up_assigned_to == user.id,
db.and_(
Inspection.follow_up_assigned_to.is_(None),
Inspection.inspector_id == user.id,
),
))
from_date_str = request.args.get('from_date')
if from_date_str:
try: