diff --git a/app/models/types_de_champ/commune_type_de_champ.rb b/app/models/types_de_champ/commune_type_de_champ.rb index 3f2766d6c..2f3d639df 100644 --- a/app/models/types_de_champ/commune_type_de_champ.rb +++ b/app/models/types_de_champ/commune_type_de_champ.rb @@ -27,6 +27,31 @@ class TypesDeChamp::CommuneTypeDeChamp < TypesDeChamp::TypeDeChampBase champ.code_postal? ? "#{champ.name} (#{champ.code_postal})" : champ.name end + def columns(procedure:, displayable: true, prefix: nil) + super.concat( + [ + Columns::JSONPathColumn.new( + procedure_id: procedure.id, + stable_id:, + tdc_type: type_champ, + label: "#{libelle_with_prefix(prefix)} - code postal (5 chiffres)", + jsonpath: '$.code_postal', + displayable:, + type: :text + ), + Columns::JSONPathColumn.new( + procedure_id: procedure.id, + stable_id:, + tdc_type: type_champ, + label: "#{libelle_with_prefix(prefix)} - département", + jsonpath: '$.code_departement', + displayable:, + type: :number + ) + ] + ) + end + private def paths diff --git a/spec/models/columns/champ_column_spec.rb b/spec/models/columns/champ_column_spec.rb index 82c0fa2bd..d21bd67f2 100644 --- a/spec/models/columns/champ_column_spec.rb +++ b/spec/models/columns/champ_column_spec.rb @@ -13,7 +13,7 @@ describe Columns::ChampColumn do expect_type_de_champ_values('email', eq(['yoda@beta.gouv.fr'])) expect_type_de_champ_values('phone', eq(['0666666666'])) expect_type_de_champ_values('address', eq(["2 rue des Démarches"])) - expect_type_de_champ_values('communes', eq(["Coye-la-Forêt"])) + expect_type_de_champ_values('communes', eq(["Coye-la-Forêt", "60580", "60"])) expect_type_de_champ_values('departements', eq(['01'])) expect_type_de_champ_values('regions', eq(['01'])) expect_type_de_champ_values('pays', eq(['France'])) diff --git a/spec/services/procedure_export_service_tabular_spec.rb b/spec/services/procedure_export_service_tabular_spec.rb index 6981b47db..b2eb2367d 100644 --- a/spec/services/procedure_export_service_tabular_spec.rb +++ b/spec/services/procedure_export_service_tabular_spec.rb @@ -52,13 +52,13 @@ describe ProcedureExportService do ExportedColumn.new(libelle: 'Groupe instructeur', column: procedure.find_column(label: 'Groupe instructeur')), ExportedColumn.new(libelle: 'État du dossier', column: procedure.dossier_state_column), ExportedColumn.new(libelle: 'first champ', column: procedure.find_column(label: 'first champ')), - ExportedColumn.new(libelle: 'Commune (Code INSEE)', column: procedure.find_column(label: 'Commune (Code INSEE)')), + ExportedColumn.new(libelle: 'Commune', column: procedure.find_column(label: 'Commune')), ExportedColumn.new(libelle: 'PJ', column: procedure.find_column(label: 'PJ')) ] end let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) } - let(:selected_headers) { ["Email", "first champ", "Commune (Code INSEE)", "Groupe instructeur", "Date du dernier évènement", "État du dossier", "PJ"] } + let(:selected_headers) { ["Email", "first champ", "Commune", "Groupe instructeur", "Date du dernier évènement", "État du dossier", "PJ"] } it 'should have only headers from export template' do expect(dossiers_sheet.headers).to match_array(selected_headers) @@ -68,7 +68,7 @@ describe ProcedureExportService do expect(procedure.dossiers.count).to eq 1 expect(dossiers_sheet.data.size).to eq 1 - expect(dossiers_sheet.data).to match_array([[anything, dossier.user_email_for_display, "défaut", "En instruction", "text", "60172", "toto.txt"]]) + expect(dossiers_sheet.data).to match_array([[anything, dossier.user_email_for_display, "défaut", "En instruction", "text", "Coye-la-Forêt", "toto.txt"]]) end end