diff --git a/app/models/concerns/dossier_champs_concern.rb b/app/models/concerns/dossier_champs_concern.rb index 70795761a..17ce89a25 100644 --- a/app/models/concerns/dossier_champs_concern.rb +++ b/app/models/concerns/dossier_champs_concern.rb @@ -81,13 +81,18 @@ module DossierChampsConcern def champs_for_export(types_de_champ, row_id = nil) types_de_champ.flat_map do |type_de_champ| - champ = champ_for_export(type_de_champ, row_id) + champ = filled_champ(type_de_champ, row_id) type_de_champ.libelles_for_export.map do |(libelle, path)| - [libelle, TypeDeChamp.champ_value_for_export(type_de_champ.type_champ, champ, path)] + [libelle, type_de_champ.champ_value_for_export(champ, path)] end end end + def champ_value_for_tag(type_de_champ, path = :value) + champ = filled_champ(type_de_champ, nil) + type_de_champ.champ_value_for_tag(champ, path) + end + def champ_for_update(type_de_champ, row_id, updated_by:) champ, attributes = champ_with_attributes_for_update(type_de_champ, row_id, updated_by:) champ.assign_attributes(attributes) @@ -143,7 +148,7 @@ module DossierChampsConcern @champs_by_public_id ||= champs.sort_by(&:id).index_by(&:public_id) end - def champ_for_export(type_de_champ, row_id) + def filled_champ(type_de_champ, row_id) champ = champs_by_public_id[type_de_champ.public_id(row_id)] if champ.blank? || !champ.visible? nil diff --git a/app/models/types_de_champ/type_de_champ_base.rb b/app/models/types_de_champ/type_de_champ_base.rb index 990c68987..e081d0e4e 100644 --- a/app/models/types_de_champ/type_de_champ_base.rb +++ b/app/models/types_de_champ/type_de_champ_base.rb @@ -15,12 +15,12 @@ class TypesDeChamp::TypeDeChampBase end def tags_for_template - tdc = @type_de_champ + type_de_champ = @type_de_champ paths.map do |path| path.merge( libelle: TagsSubstitutionConcern::TagsParser.normalize(path[:libelle]), id: path[:path] == :value ? "tdc#{stable_id}" : "tdc#{stable_id}/#{path[:path]}", - lambda: -> (dossier) { dossier.project_champ(tdc, nil).for_tag(path[:path]) } + lambda: -> (dossier) { dossier.champ_value_for_tag(type_de_champ, path[:path]) } ) end end