Merge branch 'develop' into staging

This commit is contained in:
Mathieu Magnin 2017-04-13 17:08:39 +02:00
commit ca2dca8fb5
5 changed files with 62 additions and 129 deletions

View file

@ -1,6 +1,4 @@
class Dossier < ActiveRecord::Base
include SpreadsheetArchitect
enum state: {draft: 'draft',
initiated: 'initiated',
replied: 'replied', #action utilisateur demandé
@ -233,19 +231,8 @@ class Dossier < ActiveRecord::Base
return convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr))
end
def export_default_columns
dossier_attr = DossierSerializer.new(self).attributes
dossier_attr = convert_specific_hash_values_to_string(dossier_attr)
dossier_attr = dossier_attr.merge(self.export_entreprise_data)
return dossier_attr
end
def spreadsheet_columns
self.export_default_columns.to_a
end
def data_with_champs
serialized_dossier = DossierProcedureSerializer.new(self)
serialized_dossier = DossierTableExportSerializer.new(self)
data = serialized_dossier.attributes.values
data += self.champs.order('type_de_champ_id ASC').map(&:value)
data += self.export_entreprise_data.values
@ -253,7 +240,7 @@ class Dossier < ActiveRecord::Base
end
def export_headers
serialized_dossier = DossierProcedureSerializer.new(self)
serialized_dossier = DossierTableExportSerializer.new(self)
headers = serialized_dossier.attributes.keys
headers += self.procedure.types_de_champ.order('id ASC').map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
headers += self.export_entreprise_data.keys

View file

@ -1,13 +0,0 @@
class DossierProcedureSerializer < ActiveModel::Serializer
attributes :id,
:created_at,
:updated_at,
:archived,
:mandataire_social,
:state,
:initiated_at,
:received_at,
:processed_at
attribute :followers_gestionnaires_emails, key: :emails_accompagnateurs
end

View file

@ -0,0 +1,34 @@
class DossierTableExportSerializer < ActiveModel::Serializer
attributes :id,
:created_at,
:updated_at,
:archived,
:mandataire_social,
:state,
:initiated_at,
:received_at,
:processed_at
attribute :followers_gestionnaires_emails, key: :emails_accompagnateurs
attributes :individual_gender,
:individual_prenom,
:individual_nom,
:individual_birthdate
def individual_prenom
object.individual.try(:prenom)
end
def individual_nom
object.individual.try(:nom)
end
def individual_birthdate
object.individual.try(:birthdate)
end
def individual_gender
object.individual.try(:gender)
end
end

View file

@ -1,5 +1,6 @@
FactoryGirl.define do
factory :individual do
gender 'M.'
nom 'Julien'
prenom 'Xavier'
birthdate '20/01/1991'

View file

@ -546,45 +546,6 @@ describe Dossier do
it { expect(subject.count).to eq(EntrepriseSerializer.new(Entreprise.new).as_json.count + EtablissementSerializer.new(Etablissement.new).as_json.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 }
it { expect(subject[:archived]).to eq('false') }
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 }
context 'when dossier does not have enterprise' do
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
subject { dossier.export_default_columns }
it { expect(subject[:archived]).to eq('false') }
end
end
context 'when dossier is followed' do
let(:procedure) { create(:procedure, :with_type_de_champ) }
let(:gestionnaire) { create(:gestionnaire) }
@ -598,7 +559,11 @@ describe Dossier do
subject { dossier.export_headers }
it { expect(subject).to include(:description) }
it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
it { expect(subject).to include(:individual_gender) }
it { expect(subject).to include(:individual_nom) }
it { expect(subject).to include(:individual_prenom) }
it { expect(subject).to include(:individual_birthdate) }
it { expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
end
describe '#data_with_champs' do
@ -614,7 +579,22 @@ describe Dossier do
it { expect(subject[7]).to eq(date2) }
it { expect(subject[8]).to eq(date3) }
it { expect(subject[9]).to eq(dossier.followers_gestionnaires_emails) }
it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
it { expect(subject[10]).to be_nil }
it { expect(subject[11]).to be_nil }
it { expect(subject[12]).to be_nil }
it { expect(subject[13]).to be_nil }
it { expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
context 'dossier for individual' do
let(:dossier_with_individual) { create(:dossier, :for_individual, user: user, procedure: procedure) }
subject { dossier_with_individual.data_with_champs }
it { expect(subject[10]).to eq(dossier_with_individual.individual.gender) }
it { expect(subject[11]).to eq(dossier_with_individual.individual.prenom) }
it { expect(subject[12]).to eq(dossier_with_individual.individual.nom) }
it { expect(subject[13]).to eq(dossier_with_individual.individual.birthdate) }
end
end
describe "#full_data_string" do
@ -631,6 +611,10 @@ describe Dossier do
dossier.processed_at,
gestionnaire.email,
nil,
nil,
nil,
nil,
nil,
"44011762001530",
"true",
"4950Z",
@ -664,66 +648,6 @@ describe Dossier do
end
end
describe '#Dossier.to_csv' do
let!(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure, ) }
subject do
dossier_hash = {}
dossier_splitted = Dossier.to_csv.split("\n").map { |cell| cell.split(",") }
index = 0
dossier_splitted[0].each do |column|
dossier_hash.store(column.to_sym, dossier_splitted[1][index])
index = index + 1
end
dossier_hash
end
it { expect(subject[:archived]).to eq('false') }
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('2016-01-28 10:16:29 UTC') }
it { expect(subject[:entreprise_nom]).to be_nil }
it { expect(subject[:entreprise_prenom]).to be_nil }
end
describe '#Dossier.to_xlsx' do
let!(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
subject { Dossier.to_xlsx }
it { expect(subject).is_a?(String) }
end
describe '#Dossier.to_ods' do
let!(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
subject { Dossier.to_ods }
it { expect(subject).is_a?(String) }
end
describe '#reset!' do
let!(:dossier) { create :dossier, :with_entreprise, autorisation_donnees: true }
let!(:rna_information) { create :rna_information, entreprise: dossier.entreprise }