Jul 30 - Update backend for iPad - inspector can re-inspect and create follow-up

This commit is contained in:
Nguyen Ngo
2026-07-30 16:08:58 -04:00
parent 12bcda2994
commit 5ed433aabe
5 changed files with 246 additions and 0 deletions
+21
View File
@@ -99,6 +99,20 @@ class ScheduledInspection(db.Model):
active = db.Column(db.Boolean, nullable=False, default=True)
notes = db.Column(db.Text, nullable=True)
# ── Follow-up link (phase45) ─────────────────────────────────────────────
# Set when this schedule was created as a follow-up of a specific completed
# inspection ("Schedule Follow-up" in the iPad's history detail). The
# inspection eventually started from this schedule inherits it as its
# parent_inspection_id, so it lands as a true linked re-inspection —
# pre-filled from the parent and clearing the parent's follow_up_required on
# submit. NULL = an ordinary schedule, which is what every pre-phase45 row
# is.
parent_inspection_id = db.Column(
db.Integer,
db.ForeignKey('inspections.id', ondelete='SET NULL'),
nullable=True, index=True,
)
# ── Recurrence detail (phase43) ──────────────────────────────────────────
# weekly : CSV of Python weekday ints, e.g. '0,2,4' = Mon/Wed/Fri.
# NULL/empty falls back to the legacy "every 7 days" behaviour.
@@ -126,6 +140,13 @@ class ScheduledInspection(db.Model):
template = db.relationship('InspectionTemplate', foreign_keys=[template_id])
inspector = db.relationship('User', foreign_keys=[inspector_id])
creator = db.relationship('User', foreign_keys=[created_by])
# Explicit foreign_keys is required, not optional: inspections and
# scheduled_inspections now reference each other (Inspection
# .scheduled_inspection_id points here, parent_inspection_id points back),
# so SQLAlchemy cannot infer the join for either side. Inspection
# .scheduled_inspection is already declared the same way.
parent_inspection = db.relationship('Inspection',
foreign_keys=[parent_inspection_id])
FREQUENCY_LABELS = {
'once': 'One-time',