Aug 4 - Update code to follow up - MT12b

This commit is contained in:
2026-08-04 13:37:29 -04:00
parent 73ed0157fc
commit f4c80cfcef
7 changed files with 762 additions and 2 deletions
+31
View File
@@ -151,6 +151,26 @@ class InspectionSchedule(db.Model):
mode = db.Column(db.Enum('auto', 'plan'), nullable=False, default='auto')
notes = db.Column(db.Text, nullable=True)
# ── Follow-up link (phase48) ─────────────────────────────────────────────
# 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
# deferred twin of "Re-inspect Now"). The inspection eventually started from
# this schedule inherits it as its own parent_inspection_id, so the run
# 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-phase48 row is.
parent_inspection_id = db.Column(
db.Integer,
# use_alter + an explicit name: inspections and inspection_schedules now
# reference each other, so metadata-driven CREATE/DROP cannot topologically
# sort them. The name matches the constraint phase48 creates, so the ORM's
# view of the schema and the migration's agree.
db.ForeignKey('inspections.id', ondelete='SET NULL',
name='fk_inspection_schedules_parent_inspection',
use_alter=True),
nullable=True, index=True,
)
created_by = db.Column(
db.Integer, db.ForeignKey('users.id', ondelete='SET NULL'),
nullable=True
@@ -196,6 +216,17 @@ class InspectionSchedule(db.Model):
area = db.relationship('Area', foreign_keys=[area_id])
inspector = db.relationship('User', foreign_keys=[inspector_id])
creator = db.relationship('User', foreign_keys=[created_by])
# phase48. Explicit foreign_keys is required, not optional: inspections and
# inspection_schedules now reference each other (Inspection
# .inspection_schedule_id points here, parent_inspection_id points back), so
# SQLAlchemy cannot infer the join for either side.
parent_inspection = db.relationship('Inspection',
foreign_keys=[parent_inspection_id])
@property
def is_follow_up(self):
"""True when this schedule was created to follow up an inspection."""
return self.parent_inspection_id is not None
FREQUENCY_LABELS = {
'once': 'One-time',