Prevent call for headers writting (export with procedures), get filtered dossiers by using the 'yoloServiceRegexCraftedByHandMetaForAllProject' -> extra :), adding tests for generic methods, still need to test export_columns_and_procedure
This commit is contained in:
parent
c01e3987f6
commit
a89a40df34
3 changed files with 61 additions and 5 deletions
|
@ -20,10 +20,10 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
|
||||
def download_dossiers_tps
|
||||
if procedure = Procedure.find_by(id: params[:procedure_id])
|
||||
dossiers = procedure.dossiers.where.not(state: :draft)
|
||||
dossiers = DossiersListGestionnaireService.new(current_gestionnaire, nil, procedure).filter_dossiers
|
||||
respond_with Dossier.export_columns_and_procedure(dossiers, request.format)
|
||||
else
|
||||
dossiers = current_gestionnaire.dossiers.where.not(state: :draft)
|
||||
dossiers = DossiersListGestionnaireService.new(current_gestionnaire, nil, nil).filter_dossiers
|
||||
respond_to do |format|
|
||||
format.xlsx { render xlsx: dossiers }
|
||||
format.ods { render ods: dossiers }
|
||||
|
|
|
@ -327,7 +327,7 @@ class Dossier < ActiveRecord::Base
|
|||
|
||||
def self.export_columns_and_procedure(dossiers, format)
|
||||
data = []
|
||||
headers = []
|
||||
headers = nil
|
||||
dossiers.each do |dossier|
|
||||
serialized_dossier = DossierProcedureSerializer.new(dossier).as_json[:dossier_procedure]
|
||||
champs = {}
|
||||
|
@ -336,7 +336,7 @@ class Dossier < ActiveRecord::Base
|
|||
end
|
||||
dossier_data = serialized_dossier.except(:champs).merge(champs)
|
||||
dossier_data = dossier.convert_specific_values_to_string(dossier_data)
|
||||
headers = (dossier_data.keys << dossier.export_entreprise_data.keys).flatten
|
||||
headers ||= (dossier_data.keys << dossier.export_entreprise_data.keys).flatten
|
||||
data << (dossier_data.values << dossier.export_entreprise_data.values).flatten
|
||||
end
|
||||
if ["csv"].include?(format)
|
||||
|
|
|
@ -659,7 +659,63 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#export_default_columns?' do
|
||||
describe '#convert_specific_values_to_string(hash_to_convert)' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
|
||||
let(:dossier_serialized_attributes) { DossierSerializer.new(dossier).attributes }
|
||||
|
||||
subject { dossier.convert_specific_values_to_string(dossier_serialized_attributes) }
|
||||
|
||||
it { expect(dossier_serialized_attributes[:id]).to be_an(Integer) }
|
||||
it { expect(dossier_serialized_attributes[:created_at]).to be_a(Time) }
|
||||
it { expect(dossier_serialized_attributes[:updated_at]).to be_a(Time) }
|
||||
it { expect(dossier_serialized_attributes[:archived]).to be_in([true, false]) }
|
||||
it { expect(dossier_serialized_attributes[:mandataire_social]).to be_in([true, false]) }
|
||||
it { expect(dossier_serialized_attributes[:state]).to be_a(String) }
|
||||
|
||||
it { expect(subject[:id]).to be_a(String) }
|
||||
it { expect(subject[:created_at]).to be_a(Time) }
|
||||
it { expect(subject[:updated_at]).to be_a(Time) }
|
||||
it { expect(subject[:archived]).to be_a(String) }
|
||||
it { expect(subject[:mandataire_social]).to be_a(String) }
|
||||
it { expect(subject[:state]).to be_a(String) }
|
||||
end
|
||||
|
||||
describe '#export_entreprise_data' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
|
||||
|
||||
subject { dossier.export_entreprise_data }
|
||||
|
||||
it { expect(subject[:etablissement_siret]).to eq('44011762001530') }
|
||||
it { expect(subject[:etablissement_siege_social]).to eq('true') }
|
||||
it { expect(subject[:etablissement_naf]).to eq('4950Z') }
|
||||
it { expect(subject[:etablissement_libelle_naf]).to eq('Transports par conduites') }
|
||||
it { expect(subject[:etablissement_adresse]).to eq('GRTGAZ IMMEUBLE BORA 6 RUE RAOUL NORDLING 92270 BOIS COLOMBES') }
|
||||
it { expect(subject[:etablissement_numero_voie]).to eq('6') }
|
||||
it { expect(subject[:etablissement_type_voie]).to eq('RUE') }
|
||||
it { expect(subject[:etablissement_nom_voie]).to eq('RAOUL NORDLING') }
|
||||
it { expect(subject[:etablissement_complement_adresse]).to eq('IMMEUBLE BORA') }
|
||||
it { expect(subject[:etablissement_code_postal]).to eq('92270') }
|
||||
it { expect(subject[:etablissement_localite]).to eq('BOIS COLOMBES') }
|
||||
it { expect(subject[:etablissement_code_insee_localite]).to eq('92009') }
|
||||
it { expect(subject[:entreprise_siren]).to eq('440117620') }
|
||||
it { expect(subject[:entreprise_capital_social]).to eq('537100000') }
|
||||
it { expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq('FR27440117620') }
|
||||
it { expect(subject[:entreprise_forme_juridique]).to eq("SA à conseil d'administration (s.a.i.)") }
|
||||
it { expect(subject[:entreprise_forme_juridique_code]).to eq('5599') }
|
||||
it { expect(subject[:entreprise_nom_commercial]).to eq('GRTGAZ') }
|
||||
it { expect(subject[:entreprise_raison_sociale]).to eq('GRTGAZ') }
|
||||
it { expect(subject[:entreprise_siret_siege_social]).to eq('44011762001530') }
|
||||
it { expect(subject[:entreprise_code_effectif_entreprise]).to eq('51') }
|
||||
it { expect(subject[:entreprise_date_creation]).to eq('Thu, 28 Jan 2016 10:16:29 UTC +00:0') }
|
||||
it { expect(subject[:entreprise_nom]).to be_nil }
|
||||
it { expect(subject[:entreprise_prenom]).to be_nil }
|
||||
|
||||
it { expect(subject.count).to eq(EntrepriseSerializer.new(Entreprise.new).as_json[:entreprise].count + EtablissementSerializer.new(Etablissement.new).as_json[:etablissement].count) }
|
||||
end
|
||||
|
||||
describe '#export_default_columns' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
|
||||
subject { dossier.export_default_columns }
|
||||
|
|
Loading…
Reference in a new issue