From 35458761dabce7469c77a15bd013c08e5a08a839 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 27 May 2020 17:56:50 +0200 Subject: [PATCH] fix champ etablissement --- ...0200527124112_fix_champ_etablissement.rake | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake diff --git a/lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake b/lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake new file mode 100644 index 000000000..68e6ae301 --- /dev/null +++ b/lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake @@ -0,0 +1,35 @@ +namespace :after_party do + desc 'Deployment task: fix_champ_etablissement' + task fix_champ_etablissement: :environment do + puts "Running deploy task 'fix_champ_etablissement'" + + etablissements = Etablissement.joins(:champ).where.not(dossier_id: nil).where('etablissements.created_at > ?', 1.month.ago) + dossiers_modif = [] + etablissements.find_each do |e| + if e.dossier + user = e.dossier.user + dossier = e.dossier + if user.dossiers.count == 1 && user.siret == e.champ.value + e.update!(dossier_id: nil) + dossier.etablissement = e.dup + dossier.save! + dossiers_modif << dossier.id + fetch_api_entreprise_infos(dossier.etablissement.id, dossier.procedure.id, user.id) + end + end + end + puts "Nb dossiers modifiés: #{dossiers_modif.size}" + AfterParty::TaskRecord.create version: '20200527124112' + end + + def fetch_api_entreprise_infos(etablissement_id, procedure_id, user_id) + [ + ApiEntreprise::EntrepriseJob, ApiEntreprise::AssociationJob, ApiEntreprise::ExercicesJob, + ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob, + ApiEntreprise::BilansBdfJob + ].each do |job| + job.perform_later(etablissement_id, procedure_id) + end + ApiEntreprise::AttestationFiscaleJob.perform_later(etablissement_id, procedure_id, user_id) + end +end