Deferrals, expirations, standard inspections, reminders, squawk fixes

- Squawks: defer an inoperative item under 91.213(d) once each condition
  is confirmed (pilots may too); deferred items stop grounding and are
  listed for awareness. Resolving can record the fix as a logbook entry
  (43.9 fields) or link an existing one
- Expiration dates on components (ELT battery, 91.207(c)) and documents;
  new document types (registration, airworthiness certificate, insurance,
  radio license). Expired replacement-critical parts and an expired
  registration (91.203) ground; others warn; registration warns 90 days out
- Standard inspections: one click adds annual, 100-hour, 91.411, 91.413,
  ELT (91.207(d)) and VOR (91.171) checks with the right rules, skipping
  ones already tracked and linking annual to 100-hour
- Weekly Monday reminder email to owners when something needs attention;
  profile opt-out; admin "send me this week's reminder"
- README feature table updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 10:24:33 -05:00
1 parent a4ec7a691e
commit 61c3749793
41 files changed
+649 -48

No files matched your search

+4
View File
@@ -34,6 +34,9 @@ class Component < ApplicationRecord
replacement_hours - hours_since_overhaul if replacement_hours
end
# Past the date marked on the part (it may be used through that date).
def expired?(today = Date.current) = expires_on.present? && today > expires_on
def next_replacement_date
overhaul_date + replacement_days.days if replacement_days && overhaul_date
end
@@ -49,6 +52,7 @@ class Component < ApplicationRecord
statuses << rank(Date.current >= d, Date.current + Airworthiness::DAYS_WARNING >= d)
end
end
statuses << rank(expired?, Date.current + Airworthiness::DAYS_WARNING >= expires_on) if expires_on
if tbo_critical? && tbo_hours && !on_condition?
statuses << rank(hours_to_tbo <= 0, hours_to_tbo <= Airworthiness::HOURS_WARNING * 5)
end
+10 -1
View File
@@ -4,8 +4,14 @@ class Document < ApplicationRecord
TYPES = {
"LOG" => "Logbook", "ALTER" => "Alteration Record", "REPORT" => "Report",
"ESTIMATE" => "Estimate", "DISC" => "Discrepancy List", "INVOICE" => "Receipt / Invoice",
"AIRCRAFT" => "Aircraft Record", "OTHER" => "Other"
"AIRCRAFT" => "Aircraft Record", "REGISTRATION" => "Registration Certificate",
"AIRWORTHINESS_CERT" => "Airworthiness Certificate", "INSURANCE" => "Insurance Policy",
"RADIO" => "Radio Station License", "OTHER" => "Other"
}.freeze
# An expired registration means the aircraft may not be flown (14 CFR
# 91.203(a)(2)); renewal takes a while, so warn earlier.
GROUNDING_EXPIRY_TYPES = %w[REGISTRATION].freeze
EXPIRY_WARNING_DAYS = { "REGISTRATION" => 90 }.freeze
belongs_to :aircraft
belongs_to :document_collection, optional: true
@@ -19,9 +25,12 @@ class Document < ApplicationRecord
normalizes :visibility, with: ->(v) { v.presence }
scope :ordered, -> { order(:name) }
scope :expiring, -> { where.not(expires_on: nil) }
def to_s = name
def type_label = TYPES[doc_type]
def expired?(today = Date.current) = expires_on.present? && today > expires_on
def expiry_warning_days = EXPIRY_WARNING_DAYS.fetch(doc_type, 30)
# nil visibility inherits from the collection; uncollected docs default to private.
def effective_visibility
+3
View File
@@ -6,6 +6,9 @@ class InspectionType < ApplicationRecord
"no_transponder" => "Transponder can't be used (91.413)",
"advisory" => "Advisory only"
}.freeze
# In a sentence: "Overdue: no IFR."
EFFECT_SUMMARIES = { "grounds" => "grounds the aircraft", "no_ifr" => "no IFR", "no_transponder" => "transponder can't be used",
"advisory" => "advisory only" }.freeze
# Short form for the airworthiness status ("VFR only").
LIMITATIONS = { "no_ifr" => "VFR only", "no_transponder" => "No transponder" }.freeze
+1
View File
@@ -23,6 +23,7 @@ class LogbookEntry < ApplicationRecord
belongs_to :document, optional: true
has_many :inspection_records, dependent: :nullify
has_many :ad_compliances, dependent: :nullify
has_many :squawks, dependent: :nullify
validates :date, :text, presence: true
validates :log_type, inclusion: { in: LOG_TYPES.keys }
+41 -5
View File
@@ -7,6 +7,7 @@ class Squawk < ApplicationRecord
belongs_to :aircraft
belongs_to :component, optional: true
belongs_to :reported_by, class_name: "User", optional: true
belongs_to :logbook_entry, optional: true
has_many_attached :attachments
validates :priority, inclusion: { in: PRIORITIES.keys }
@@ -17,11 +18,46 @@ class Squawk < ApplicationRecord
scope :resolved, -> { where(resolved: true) }
scope :by_priority, -> { order(:priority, created_at: :desc) }
def priority_label = PRIORITIES[priority]
def priority_color = PRIORITY_COLORS[priority]
def grounding? = priority.zero? && !resolved?
# Deferring inoperative equipment without an MEL, 14 CFR 91.213(d): what
# was done with the item and who decided it isn't a hazard.
DEFERRAL_ACTIONS = { "deactivated" => "Deactivated and placarded \"Inoperative\"",
"removed" => "Removed, cockpit control placarded \"Inoperative\"" }.freeze
DEFERRAL_ROLES = { "pilot" => "Pilot", "mechanic" => "Certificated mechanic" }.freeze
# Each must be confirmed to defer (91.213(d)(2)(i)–(iv) and (d)(3)–(4)).
DEFERRAL_CHECKS = {
"not_required_by_type" => "Not part of the VFR-day type certification instruments and equipment, nor on the aircraft's equipment list or kinds of operations equipment list",
"not_required_by_rules" => "Not required by 91.205 or any other rule for the kind of flight planned",
"not_required_by_ad" => "Not required by an airworthiness directive",
"placarded" => "Removed or deactivated, and placarded \"Inoperative\"",
"no_hazard" => "A pilot or certificated mechanic has determined it isn't a hazard to the aircraft"
}.freeze
def resolve!(notes: nil)
update!(resolved: true, resolved_at: Time.current, notes: [ self.notes, notes ].compact_blank.join("\n\n"))
scope :deferred, -> { active.where.not(deferred_at: nil) }
validates :deferral_action, inclusion: { in: DEFERRAL_ACTIONS.keys }, if: :deferred?
validates :deferred_by_role, inclusion: { in: DEFERRAL_ROLES.keys }, if: :deferred?
validates :deferred_by_name, presence: true, if: :deferred?
def priority_label = deferred? ? "Deferred (91.213(d))" : PRIORITIES[priority]
def priority_color = deferred? ? "blue" : PRIORITY_COLORS[priority]
def deferred? = deferred_at.present? && !resolved?
def grounding? = priority.zero? && !resolved? && !deferred?
def deferral_action_label = DEFERRAL_ACTIONS[deferral_action]
# Defers the item if every check is confirmed; returns false with errors otherwise.
def defer(checks:, name:, role:, action:, notes: nil)
missing = DEFERRAL_CHECKS.keys - Array(checks).map(&:to_s)
assign_attributes(deferred_at: Time.current, deferred_by_name: name.to_s.strip.presence, deferred_by_role: role,
deferral_action: action, deferral_notes: notes.to_s.strip.presence)
missing.each { errors.add(:base, "Confirm: #{DEFERRAL_CHECKS[_1]}") }
return false if missing.any? || !valid?
save
end
def undefer! = update!(deferred_at: nil, deferred_by_name: nil, deferred_by_role: nil, deferral_action: nil, deferral_notes: nil)
def resolve!(notes: nil, logbook_entry: nil)
update!(resolved: true, resolved_at: Time.current, logbook_entry: logbook_entry || self.logbook_entry,
notes: [ self.notes, notes ].compact_blank.join("\n\n"))
end
end
+53
View File
@@ -0,0 +1,53 @@
# The recurring inspections and checks Part 91 calls for, to add to an
# aircraft in one go (Inspections → Standard inspections).
module StandardInspections
Template = Data.define(:key, :name, :who, :months, :days, :hours, :tolerance, :effect, :checked, :pattern) do
def attributes
{ name: name, recurring: true, recurring_months: months.to_i, recurring_days: days.to_i,
recurring_hours: hours.to_i, hours_tolerance: tolerance.to_i, effect: effect }
end
end
TEMPLATES = [
Template.new(key: "annual", name: "Annual inspection (91.409(a))", who: "Every aircraft",
months: 12, days: nil, hours: nil, tolerance: nil, effect: "grounds", checked: true, pattern: /annual/i),
Template.new(key: "hundred", name: "100-hour inspection (91.409(b))", who: "Carrying anyone for hire, or flight instruction for hire",
months: nil, days: nil, hours: 100, tolerance: 10, effect: "grounds", checked: false, pattern: /100[- ]?h(ou)?r/i),
Template.new(key: "transponder", name: "Transponder check (91.413)", who: "Aircraft with a transponder",
months: 24, days: nil, hours: nil, tolerance: nil, effect: "no_transponder", checked: true, pattern: /transponder|91\.413/i),
Template.new(key: "pitot_static", name: "Altimeter and static system check (91.411)", who: "Flying IFR in controlled airspace",
months: 24, days: nil, hours: nil, tolerance: nil, effect: "no_ifr", checked: false, pattern: /pitot|static|altimeter|91\.411/i),
Template.new(key: "elt", name: "ELT inspection (91.207(d))", who: "Aircraft required to carry an ELT",
months: 12, days: nil, hours: nil, tolerance: nil, effect: "grounds", checked: true, pattern: /\belt\b|91\.207/i),
Template.new(key: "vor", name: "VOR check (91.171)", who: "Flying IFR using VORs; the pilot may do and log it",
months: nil, days: 30, hours: nil, tolerance: nil, effect: "no_ifr", checked: false, pattern: /\bvor\b|91\.171/i)
].freeze
module_function
def find(key) = TEMPLATES.find { _1.key == key }
# The aircraft's existing inspection type a template matches, if any.
def existing_for(template, aircraft)
aircraft.applicable_inspection_types.find { _1.name.match?(template.pattern) }
end
# Adds the chosen templates the aircraft doesn't already track. Returns the
# inspection types added.
def add!(aircraft, keys)
added = {}
InspectionType.transaction do
Array(keys).filter_map { find(_1.to_s) }.each do |t|
next if existing_for(t, aircraft)
type = InspectionType.find_by(name: t.name) || InspectionType.create!(t.attributes)
type.aircraft << aircraft unless type.aircraft.include?(aircraft)
added[t.key] = type
end
# An annual also counts as the 100-hour (91.409(b)).
annual = added["annual"] || (find("annual") && existing_for(find("annual"), aircraft))
hundred = added["hundred"] || existing_for(find("hundred"), aircraft)
annual.update!(satisfies: hundred) if annual && hundred && annual.satisfies_id.nil? && (added["annual"] || added["hundred"])
end
added.values
end
end