diff --git a/app/models/concerns/dossier_champs_concern.rb b/app/models/concerns/dossier_champs_concern.rb index 7ab2dc65d..8e1f3d57a 100644 --- a/app/models/concerns/dossier_champs_concern.rb +++ b/app/models/concerns/dossier_champs_concern.rb @@ -57,7 +57,7 @@ module DossierChampsConcern revision .types_de_champ .filter { _1.stable_id.in?(stable_ids) } - .filter { !revision.child?(_1) } + .filter { !_1.child?(revision) } .map { _1.repetition? ? project_champ(_1, nil) : champ_for_update(_1, nil, updated_by: nil) } end @@ -129,7 +129,7 @@ module DossierChampsConcern end def check_valid_row_id?(type_de_champ, row_id) - if revision.child?(type_de_champ) + if type_de_champ.child?(revision) if row_id.blank? raise "type_de_champ #{type_de_champ.stable_id} must have a row_id because it is part of a repetition" end diff --git a/app/models/concerns/dossier_sections_concern.rb b/app/models/concerns/dossier_sections_concern.rb index 679e5b896..c4644dba3 100644 --- a/app/models/concerns/dossier_sections_concern.rb +++ b/app/models/concerns/dossier_sections_concern.rb @@ -19,7 +19,7 @@ module DossierSectionsConcern end def auto_numbering_section_headers_for?(type_de_champ) - return false if revision.child?(type_de_champ) + return false if type_de_champ.child?(revision) sections_for(type_de_champ)&.none? { _1.libelle =~ /^\d/ } end diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index d1073e5e5..88c9f7dbf 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -219,11 +219,6 @@ class ProcedureRevision < ApplicationRecord .find { _1.type_de_champ_id == tdc.id }.parent&.type_de_champ end - def child?(tdc) - revision_types_de_champ - .find { _1.type_de_champ_id == tdc.id }&.child? - end - def remove_children_of(tdc) children_of(tdc).each do |child| remove_type_de_champ(child.stable_id) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 0fd8333df..8217a53c3 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -456,6 +456,10 @@ class TypeDeChamp < ApplicationRecord !private? end + def child?(revision) + revision.revision_types_de_champ.find { _1.type_de_champ_id == id }&.child? + end + def filename_for_attachement(attachment_sym) attachment = send(attachment_sym) if attachment.attached?