Merge pull request #9488 from colinux/fix-prefill-siret

Fix dossiers préremplis avec identité individuelle vide de démarches pour établissements
This commit is contained in:
LeSim 2023-09-19 07:58:41 +00:00 committed by GitHub
commit 5d3a637ccb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View file

@ -8,7 +8,7 @@ module DossierPrefillableConcern
attributes = { prefilled: true } attributes = { prefilled: true }
attributes[:champs_attributes] = champs_attributes.map { |h| h.merge(prefilled: true) } attributes[:champs_attributes] = champs_attributes.map { |h| h.merge(prefilled: true) }
attributes[:individual_attributes] = identity_attributes attributes[:individual_attributes] = identity_attributes if identity_attributes.present?
assign_attributes(attributes) assign_attributes(attributes)
save(validate: false) save(validate: false)

View file

@ -0,0 +1,16 @@
namespace :after_party do
desc 'Deployment task: fix_prefilled_empty_individual'
task fix_prefilled_empty_individual: :environment do
puts "Running deploy task 'fix_prefilled_empty_individual'"
Dossier.prefilled.joins(:procedure).joins(:individual).where(procedure: { for_individual: false }).find_each do |dossier|
rake_puts "Destroy Individual of dossier ##{dossier.id}"
dossier.individual.destroy!
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -101,6 +101,29 @@ RSpec.describe DossierPrefillableConcern do
end end
end end
context "when dossier is for etablissement" do
let(:procedure) { create(:procedure, :published, types_de_champ_public:, types_de_champ_private:) }
let(:dossier) { create(:dossier, :brouillon, procedure: procedure) }
context 'when champs_attributes has values' do
context 'when the champs are valid' do
let(:types_de_champ_public) { [{ type: :text }] }
let(:type_de_champ_1) { procedure.published_revision.types_de_champ_public.first }
let(:value_1) { "any value" }
let(:champ_id_1) { find_champ_by_stable_id(dossier, type_de_champ_1.stable_id).id }
let(:values) { [{ id: champ_id_1, value: value_1 }] }
it "updates the champs with the new values and mark them as prefilled" do
fill
expect(dossier.champs_public.first.value).to eq(value_1)
expect(dossier.individual).to be_nil # Fix #9486
end
it_behaves_like 'a dossier marked as prefilled'
end
end
end
private private
def find_champ_by_stable_id(dossier, stable_id) def find_champ_by_stable_id(dossier, stable_id)