refactor(attestation): unspecified_champs_for_dossier based on types_de_champ

This commit is contained in:
Paul Chavard 2024-08-22 17:36:31 +02:00
parent 1aee7ab1d2
commit 5edb8749c0
No known key found for this signature in database

View file

@ -87,13 +87,13 @@ class AttestationTemplate < ApplicationRecord
end end
def unspecified_champs_for_dossier(dossier) def unspecified_champs_for_dossier(dossier)
champs_by_stable_id = dossier.champs_for_revision(root: true).index_by { "tdc#{_1.stable_id}" } types_de_champ_by_tag_id = dossier.revision.types_de_champ.index_by { "tdc#{_1.stable_id}" }
used_tags.filter_map do |used_tag| used_tags.filter_map do |used_tag|
corresponding_champ = champs_by_stable_id[used_tag] corresponding_type_de_champ = types_de_champ_by_tag_id[used_tag]
if corresponding_champ && corresponding_champ.blank? if corresponding_type_de_champ && dossier.project_champ(corresponding_type_de_champ, nil).blank?
corresponding_champ corresponding_type_de_champ
end end
end end
end end