Fix export dossier (#4151)

Correction de l'export tableur des dossiers v2
This commit is contained in:
Pierre de La Morinerie 2019-07-30 17:31:51 +02:00 committed by GitHub
commit 25f49acbd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 10 deletions

View file

@ -108,7 +108,24 @@ class Dossier < ApplicationRecord
scope :en_construction, -> { not_archived.state_en_construction }
scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine }
scope :downloadable_sorted, -> { state_not_brouillon.includes(:etablissement, :user, :individual, :followers_gestionnaires, :avis, champs: { etablissement: [:champ], type_de_champ: :drop_down_list }, champs_private: { etablissement: [:champ], type_de_champ: :drop_down_list }).order(en_construction_at: 'asc') }
scope :downloadable_sorted, -> {
state_not_brouillon
.includes(
:user,
:individual,
:followers_gestionnaires,
:avis,
etablissement: :champ,
champs: {
etablissement: :champ,
type_de_champ: :drop_down_list
},
champs_private: {
etablissement: :champ,
type_de_champ: :drop_down_list
}
).order(en_construction_at: 'asc')
}
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) }

View file

@ -120,6 +120,6 @@ class Etablissement < ApplicationRecord
end
def libelle_for_export
champ&.libelle
champ&.libelle || 'Dossier'
end
end

View file

@ -53,16 +53,18 @@ class ProcedureExportV2Service
[dossier.champs, dossier.champs_private]
.flatten
.select { |champ| champ.is_a?(Champs::RepetitionChamp) }
end
end.group_by(&:libelle)
end
def champs_repetables_options
champs_repetables.map do |champ|
champs_repetables.map do |libelle, champs|
[
champ.libelle,
libelle,
champs.flat_map do |champ|
champ.rows.each_with_index.map do |champs, index|
Champs::RepetitionChamp::Row.new(index: index + 1, dossier_id: champ.dossier_id.to_s, champs: champs)
end
end
]
end
end

View file

@ -93,6 +93,9 @@ describe ProcedureExportV2Service do
context 'with etablissement' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_entreprise, procedure: procedure) }
let(:dossier_etablissement) { etablissements_sheet.data[1] }
let(:champ_etablissement) { etablissements_sheet.data[0] }
it 'should have headers' do
expect(etablissements_sheet.headers).to eq([
"Dossier ID",
@ -132,6 +135,8 @@ describe ProcedureExportV2Service do
it 'should have data' do
expect(etablissements_sheet.data.size).to eq(2)
expect(dossier_etablissement[1]).to eq("Dossier")
expect(champ_etablissement[1]).to eq("siret")
end
end
@ -155,8 +160,13 @@ describe ProcedureExportV2Service do
end
context 'with repetitions' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure) }
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
let!(:dossiers) do
[
create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure),
create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure)
]
end
let(:champ_repetition) { dossiers.first.champs.find { |champ| champ.type_champ == 'repetition' } }
it 'should have sheets' do
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.libelle])
@ -172,7 +182,7 @@ describe ProcedureExportV2Service do
end
it 'should have data' do
expect(repetition_sheet.data.size).to eq(2)
expect(repetition_sheet.data.size).to eq(4)
end
end
end