Ordering champs through export method, not through serializer

This commit is contained in:
JC 2016-11-14 16:37:58 +01:00
parent 5c3049d6bd
commit 5aa9c75669
2 changed files with 15 additions and 22 deletions

View file

@ -331,26 +331,26 @@ class Dossier < ActiveRecord::Base
end end
def data_with_champs def data_with_champs
data = [] serialized_dossier = DossierProcedureSerializer.new(self)
serialized_dossier = DossierProcedureSerializer.new(self).as_json[:dossier_procedure] data = serialized_dossier.attributes.values
champs = {} data += self.champs.order('type_de_champ_id ASC').map(&:value)
serialized_dossier[:champs].each do |champ_hash| data += self.export_entreprise_data.values
champs[champ_hash[:type_de_champ]["libelle"].parameterize.underscore.to_sym] = champ_hash[:value] return data
end end
binding.pry
dossier_data = serialized_dossier.except(:champs).merge(champs) def export_headers
dossier_data = self.convert_specific_values_to_string(dossier_data) serialized_dossier = DossierProcedureSerializer.new(self)
return dossier_data.merge(self.export_entreprise_data) 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
return headers
end end
def self.export_full_generation(dossiers, format) def self.export_full_generation(dossiers, format)
data = [] data = []
headers = [] headers = dossiers.first.export_headers
dossiers.each do |dossier| dossiers.each do |dossier|
if dossier.id == 948 || dossier.id == 955 data << dossier.data_with_champs
data << dossier.data_with_champs.values
headers = dossier.data_with_champs.keys if headers.empty?
end
end end
if ["csv"].include?(format) if ["csv"].include?(format)
return SpreadsheetArchitect.to_csv(data: data, headers: headers) return SpreadsheetArchitect.to_csv(data: data, headers: headers)

View file

@ -5,11 +5,4 @@ class DossierProcedureSerializer < ActiveModel::Serializer
:archived, :archived,
:mandataire_social, :mandataire_social,
:state :state
has_many :champs
def champs
object.champs.order("type_de_champ_id")
end
end end