Sub-components on logbook entries (e.g. the oil filter on the engine)

- Once a component is chosen, its sub-components are offered on the entry
  form (and the squawk Resolve page); ticked ones are saved with their
  total time and time since service, worked out from the airframe total
  time like the component's (editable; blank before it was installed)
- Entry page and printed PDFs list each sub-component with its serial
  number and times; parts without an overhaul type read "Since service"
- Archives carry them: the original format's list of components per entry
  (first = the entry's component, the rest = sub-components)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 12:54:49 -05:00
1 parent 72e1d7760f
commit 7caa213e7a
16 files changed
+249 -22

No files matched your search

+6 -4
View File
@@ -55,7 +55,7 @@ module AircraftArchive
document_images: a.documents.includes(pages_attachments: :blob).flat_map do |d|
d.pages.map { |page| { id: id(page), document_id: id(d), notes: "", image: file(page, "health/documents") } }
end,
logbook_entries: a.logbook_entries.map { logbook_hash(_1) },
logbook_entries: a.logbook_entries.includes(:parts).map { logbook_hash(_1) },
squawks: a.squawks.includes(:reported_by, attachments_attachments: :blob).map { squawk_hash(_1) },
inspection_types: inspection_types.map { inspection_type_hash(_1, component_ids) },
inspection_records: a.inspection_records.map do |r|
@@ -148,9 +148,11 @@ module AircraftArchive
inspection_result: e.inspection_result, verified: e.verified, transcription_confidence: e.transcription_confidence,
log_image_id: id(e.document_id),
aircraft_hours_at_entry: dec(e.aircraft_hours_at_entry), entry_type: e.entry_type, page_number: e.page_number,
components: [ id(e.component_id) ].compact,
component_hours: e.component_id ? { id(e.component_id) => dec(e.component_hours_at_entry) }.compact : {},
component_since_overhaul: e.component_id ? { id(e.component_id) => dec(e.component_since_overhaul_at_entry) }.compact : {},
components: [ id(e.component_id), *e.parts.map { id(_1.component_id) } ].compact,
component_hours: { id(e.component_id) => dec(e.component_hours_at_entry) }.merge(e.parts.to_h { [ id(_1.component_id), dec(_1.hours_at_entry) ] })
.reject { |k, v| k.nil? || v.nil? },
component_since_overhaul: { id(e.component_id) => dec(e.component_since_overhaul_at_entry) }
.merge(e.parts.to_h { [ id(_1.component_id), dec(_1.since_overhaul_at_entry) ] }).reject { |k, v| k.nil? || v.nil? },
related_documents: [] }
end
+8 -6
View File
@@ -222,7 +222,6 @@ module AircraftArchive
end
def import_logbook
dropped = 0
m("logbook_entries").each do |data|
e = @aircraft.logbook_entries.new(
log_type: LogbookEntry::LOG_TYPES.key?(data["log_type"]) ? data["log_type"] : "AC",
@@ -237,19 +236,22 @@ module AircraftArchive
aircraft_hours_at_entry: num(data["aircraft_hours_at_entry"]), page_number: data["page_number"],
document_id: @map[:document][data["log_image_id"].to_s]
)
# One component per entry here (the original allows several): the first, with its times.
if (ref = Array(data["components"]).first) && (component_id = @map[:component][ref.to_s])
e.component_id = component_id
# The first component is the entry's; the rest are its sub-components, each with its times.
refs = Array(data["components"]).select { @map[:component][_1.to_s] }
if (ref = refs.first)
e.component_id = @map[:component][ref.to_s]
e.component_hours_at_entry = num(hash_value(data["component_hours"], ref))
e.component_since_overhaul_at_entry = num(hash_value(data["component_since_overhaul"], ref))
dropped += 1 if Array(data["components"]).size > 1
end
refs.drop(1).uniq.each do |r|
e.parts.build(component_id: @map[:component][r.to_s], hours_at_entry: num(hash_value(data["component_hours"], r)),
since_overhaul_at_entry: num(hash_value(data["component_since_overhaul"], r)))
end
e.save!(validate: false)
@map[:logbook][data["id"].to_s] = e.id
tick("logbook_entries")
end
warn("#{dropped} logbook #{dropped == 1 ? 'entry was' : 'entries were'} linked to several components; only the first is kept here.") if dropped.positive?
end
def import_squawks