Merge pull request #4346 from betagouv/add_groupe_instructeur_column_in_export

Ajoute la colonne groupe d'instructeur dans les procédures routées
This commit is contained in:
LeSim 2019-09-19 17:12:03 +02:00 committed by GitHub
commit d2b9e9102a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 11 deletions

View file

@ -126,7 +126,8 @@ class Dossier < ApplicationRecord
champs_private: {
etablissement: :champ,
type_de_champ: :drop_down_list
}
},
procedure: :groupe_instructeurs
).order(en_construction_at: 'asc')
}
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
@ -447,7 +448,7 @@ class Dossier < ApplicationRecord
end
def spreadsheet_columns
[
columns = [
['ID', id.to_s],
['Email', user.email],
['Civilité', individual&.gender],
@ -462,7 +463,13 @@ class Dossier < ApplicationRecord
['Traité le', :processed_at],
['Motivation de la décision', :motivation],
['Instructeurs', followers_instructeurs.map(&:email).join(' ')]
] + champs_for_export + annotations_for_export
]
if procedure.routee?
columns << ['Groupe instructeur', groupe_instructeur.label]
end
columns + champs_for_export + annotations_for_export
end
def champs_for_export

View file

@ -481,6 +481,10 @@ class Procedure < ApplicationRecord
!AssignTo.exists?(groupe_instructeur: groupe_instructeurs)
end
def routee?
groupe_instructeurs.count > 1
end
private
def move_type_de_champ_attributes(types_de_champ, type_de_champ, new_index)

View file

@ -51,6 +51,13 @@ class ProcedureExportService
def initialize(procedure, dossiers, tables: [], ids: nil, since: nil, limit: nil)
@procedure = procedure
@attributes = ATTRIBUTES.dup
if procedure.routee?
@attributes << :groupe_instructeur_label
end
@dossiers = dossiers.downloadable_sorted
if ids
@dossiers = @dossiers.where(id: ids)
@ -137,7 +144,7 @@ class ProcedureExportService
end
def dossiers_headers
headers = ATTRIBUTES.map(&:to_s) +
headers = @attributes.map(&:to_s) +
@procedure.types_de_champ.reject(&:exclude_from_export?).map(&:libelle) +
@procedure.types_de_champ_private.reject(&:exclude_from_export?).map(&:libelle) +
ETABLISSEMENT_ATTRIBUTES.map { |key| "etablissement.#{key}" } +
@ -148,7 +155,7 @@ class ProcedureExportService
def dossiers_data
@dossiers.map do |dossier|
values = ATTRIBUTES.map do |key|
values = @attributes.map do |key|
case key
when :email
dossier.user.email
@ -168,6 +175,8 @@ class ProcedureExportService
dossier.individual&.gender
when :emails_instructeurs
dossier.followers_instructeurs.map(&:email).join(' ')
when :groupe_instructeur_label
dossier.groupe_instructeur.label
else
dossier.read_attribute(key)
end

View file

@ -19,8 +19,8 @@ describe ProcedureExportService do
end
context 'dossiers' do
it 'should have headers' do
expect(headers).to eq([
let(:nominal_header) do
[
:id,
:created_at,
:updated_at,
@ -86,7 +86,19 @@ describe ProcedureExportService do
:entreprise_date_creation,
:entreprise_nom,
:entreprise_prenom
])
]
end
it 'should have headers' do
expect(headers).to eq(nominal_header)
end
context 'with a procedure routee' do
before { procedure.groupe_instructeurs.create(label: '2') }
let(:routee_header) { nominal_header.insert(nominal_header.index(:textarea), :groupe_instructeur_label) }
it { expect(headers).to eq(routee_header) }
end
it 'should have empty values' do
@ -139,6 +151,13 @@ describe ProcedureExportService do
])
end
context 'with a procedure routee' do
before { procedure.groupe_instructeurs.create(label: '2') }
it { expect(data.first[15]).to eq('défaut') }
it { expect(data.first.count).to eq(dossier_data.count + champs_data.count + etablissement_data.count + 1) }
end
context 'and etablissement' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_entreprise, procedure: procedure) }

View file

@ -34,8 +34,8 @@ describe ProcedureExportV2Service do
context 'with dossier' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure) }
it 'should have headers' do
expect(dossiers_sheet.headers).to eq([
let(:nominal_headers) do
[
"ID",
"Email",
"Civilité",
@ -74,7 +74,11 @@ describe ProcedureExportV2Service do
"siret",
"carte",
"text"
])
]
end
it 'should have headers' do
expect(dossiers_sheet.headers).to match(nominal_headers)
end
it 'should have data' do
@ -88,6 +92,15 @@ describe ProcedureExportV2Service do
expect(en_construction_at).to eq(dossier.en_construction_at.round)
expect(en_instruction_at).to eq(dossier.en_instruction_at.round)
end
context 'with a procedure routee' do
before { procedure.groupe_instructeurs.create(label: '2') }
let(:routee_header) { nominal_headers.insert(nominal_headers.index('textarea'), 'Groupe instructeur') }
it { expect(dossiers_sheet.headers).to match(routee_header) }
it { expect(dossiers_sheet.data[0][dossiers_sheet.headers.index('Groupe instructeur')]).to eq('défaut') }
end
end
context 'with etablissement' do