add code insee libelle for commune export

This commit is contained in:
Christophe Robillard 2021-08-18 14:13:10 +02:00
parent 4a6c22d6a6
commit e06f11f33f
6 changed files with 19 additions and 3 deletions

View file

@ -883,8 +883,8 @@ class Dossier < ApplicationRecord
# Get all the champs values for the types de champ in the final list. # Get all the champs values for the types de champ in the final list.
# Dossier might not have corresponding champ display nil. # Dossier might not have corresponding champ display nil.
types_de_champ.flat_map do |type_de_champ| types_de_champ.flat_map do |type_de_champ|
Array.wrap(values[type_de_champ.stable_id] || [nil]).map do |champ_value, index| Array.wrap(values[type_de_champ.stable_id] || [nil]).map.with_index do |champ_value, index|
[type_de_champ.libelle, champ_value] [type_de_champ.libelle_for_export(index), champ_value]
end end
end end
end end

View file

@ -61,7 +61,7 @@ class TypeDeChamp < ApplicationRecord
has_many :revision_types_de_champ, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ has_many :revision_types_de_champ, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ
has_many :revisions, through: :revision_types_de_champ has_many :revisions, through: :revision_types_de_champ
delegate :tags_for_template, to: :dynamic_type delegate :tags_for_template, :libelle_for_export, to: :dynamic_type
class WithIndifferentAccess class WithIndifferentAccess
def self.load(options) def self.load(options)

View file

@ -1,2 +1,5 @@
class TypesDeChamp::CommuneTypeDeChamp < TypesDeChamp::TypeDeChampBase class TypesDeChamp::CommuneTypeDeChamp < TypesDeChamp::TypeDeChampBase
def libelle_for_export(index)
[libelle, "#{libelle} (Code insee)"][index]
end
end end

View file

@ -21,6 +21,10 @@ class TypesDeChamp::TypeDeChampBase
] ]
end end
def libelle_for_export(index)
libelle
end
def build_champ def build_champ
@type_de_champ.champ.build @type_de_champ.champ.build
end end

View file

@ -0,0 +1,6 @@
describe TypesDeChamp::CommuneTypeDeChamp do
let(:subject) { create(:type_de_champ_communes, libelle: 'Ma commune') }
it { expect(subject.libelle_for_export(0)).to eq('Ma commune') }
it { expect(subject.libelle_for_export(1)).to eq('Ma commune (Code insee)') }
end

View file

@ -68,6 +68,7 @@ describe ProcedureExportService do
"regions", "regions",
"departements", "departements",
"communes", "communes",
"communes (Code insee)",
"engagement", "engagement",
"dossier_link", "dossier_link",
"piece_justificative", "piece_justificative",
@ -154,6 +155,7 @@ describe ProcedureExportService do
"regions", "regions",
"departements", "departements",
"communes", "communes",
"communes (Code insee)",
"engagement", "engagement",
"dossier_link", "dossier_link",
"piece_justificative", "piece_justificative",
@ -236,6 +238,7 @@ describe ProcedureExportService do
"regions", "regions",
"departements", "departements",
"communes", "communes",
"communes (Code insee)",
"engagement", "engagement",
"dossier_link", "dossier_link",
"piece_justificative", "piece_justificative",