mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
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:
1 parent
72e1d7760f
commit
7caa213e7a
16 files changed
+249
-22
No files matched your search
+15
-1
@@ -15,6 +15,7 @@ class Component < ApplicationRecord
|
||||
has_many :inspection_records, dependent: :nullify
|
||||
has_many :major_records, dependent: :nullify
|
||||
has_many :logbook_entries, dependent: :nullify
|
||||
has_many :logbook_entry_parts, dependent: :destroy
|
||||
has_and_belongs_to_many :inspection_types
|
||||
has_and_belongs_to_many :airworthiness_directives
|
||||
|
||||
@@ -30,7 +31,20 @@ class Component < ApplicationRecord
|
||||
end
|
||||
|
||||
def status_label = STATUSES[status]
|
||||
def since_overhaul_abbreviation = OVERHAUL_ABBREVIATIONS.fetch(overhaul_kind, "TSO")
|
||||
# SMOH / SFOH / SNEW when the overhaul type is known; engines and
|
||||
# propellers otherwise "TSO", and other parts (filters…) "since service".
|
||||
def since_overhaul_abbreviation
|
||||
OVERHAUL_ABBREVIATIONS.fetch(overhaul_kind) { engine? || propeller? ? "TSO" : "Since service" }
|
||||
end
|
||||
|
||||
# Its sub-components, and theirs.
|
||||
def descendant_ids
|
||||
child_components.flat_map { [ _1.id, *_1.descendant_ids ] }
|
||||
end
|
||||
|
||||
def ancestor_ids
|
||||
parent_component ? [ parent_component_id, *parent_component.ancestor_ids ] : []
|
||||
end
|
||||
def engine? = component_type&.name.to_s.match?(/engine/i)
|
||||
def propeller? = component_type&.name.to_s.match?(/propell?er|\bprop\b/i)
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ class LogbookEntry < ApplicationRecord
|
||||
belongs_to :document, optional: true
|
||||
# For engine / propeller logs: which one, and its times at this entry.
|
||||
belongs_to :component, optional: true
|
||||
# Sub-components it also covers (the oil filter on the engine…).
|
||||
has_many :parts, -> { includes(component: :component_type).order(:id) }, class_name: "LogbookEntryPart",
|
||||
dependent: :destroy, autosave: true
|
||||
has_many :inspection_records, dependent: :nullify
|
||||
has_many :ad_compliances, dependent: :nullify
|
||||
has_many :squawks, dependent: :nullify
|
||||
@@ -45,6 +48,18 @@ class LogbookEntry < ApplicationRecord
|
||||
end
|
||||
|
||||
def to_s = "#{date} — #{LOG_TYPES[log_type]}"
|
||||
|
||||
# From the form: { component_id => { "include" => "1", "hours" => …, "since" => … } }.
|
||||
# Only the aircraft's sub-components of the entry's component are kept.
|
||||
def assign_parts(params, aircraft)
|
||||
allowed = component ? component.descendant_ids.to_set & aircraft.component_ids.to_set : Set.new
|
||||
wanted = params.to_h.select { |id, p| p["include"] == "1" && allowed.include?(id.to_i) }
|
||||
parts.each { |part| part.mark_for_destruction unless wanted.key?(part.component_id.to_s) }
|
||||
wanted.each do |id, p|
|
||||
part = parts.find { _1.component_id == id.to_i } || parts.build(component_id: id.to_i)
|
||||
part.assign_attributes(hours_at_entry: p["hours"].presence, since_overhaul_at_entry: p["since"].presence)
|
||||
end
|
||||
end
|
||||
def certificate_label = CERTIFICATE_TYPES[signoff_certificate_type]
|
||||
def inspection_result_label = INSPECTION_RESULTS[inspection_result]
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# A sub-component a logbook entry also covers (the oil filter on the engine…)
|
||||
# and its times at the entry.
|
||||
class LogbookEntryPart < ApplicationRecord
|
||||
belongs_to :logbook_entry
|
||||
belongs_to :component
|
||||
|
||||
validates :component_id, uniqueness: { scope: :logbook_entry_id }
|
||||
validates :hours_at_entry, :since_overhaul_at_entry, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
||||
end
|
||||
Reference in new issue
Block a user