dossiers: make build_default_individual
explicit
It avoid the use of callbacks, and may avoid situations where an empty individual is implicitely created.
This commit is contained in:
parent
5e05556ee8
commit
b3558c497d
3 changed files with 12 additions and 8 deletions
|
@ -231,11 +231,13 @@ module Users
|
|||
return redirect_to url_for dossiers_path
|
||||
end
|
||||
|
||||
dossier = Dossier.create!(
|
||||
dossier = Dossier.new(
|
||||
groupe_instructeur: procedure.defaut_groupe_instructeur,
|
||||
user: current_user,
|
||||
state: Dossier.states.fetch(:brouillon)
|
||||
)
|
||||
dossier.build_default_individual
|
||||
dossier.save!
|
||||
|
||||
if dossier.procedure.for_individual
|
||||
redirect_to identite_dossier_path(dossier)
|
||||
|
|
|
@ -207,9 +207,6 @@ class Dossier < ApplicationRecord
|
|||
delegate :france_connect_information, to: :user
|
||||
|
||||
before_validation :update_state_dates, if: -> { state_changed? }
|
||||
before_validation :build_default_individual,
|
||||
if: -> { new_record? && procedure.for_individual? && individual.blank? }
|
||||
|
||||
before_save :build_default_champs, if: Proc.new { groupe_instructeur_id_was.nil? }
|
||||
before_save :update_search_terms
|
||||
|
||||
|
@ -241,10 +238,12 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def build_default_individual
|
||||
self.individual = if france_connect_information.present?
|
||||
Individual.from_france_connect(france_connect_information)
|
||||
else
|
||||
Individual.new
|
||||
if procedure.for_individual? && individual.blank?
|
||||
self.individual = if france_connect_information.present?
|
||||
Individual.from_france_connect(france_connect_information)
|
||||
else
|
||||
Individual.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,9 +15,12 @@ FactoryBot.define do
|
|||
procedure = create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private)
|
||||
end
|
||||
|
||||
# Assign the procedure to the dossier through the groupe_instructeur
|
||||
if dossier.groupe_instructeur.nil?
|
||||
dossier.groupe_instructeur = procedure.defaut_groupe_instructeur
|
||||
end
|
||||
|
||||
dossier.build_default_individual
|
||||
end
|
||||
|
||||
trait :with_entreprise do
|
||||
|
|
Loading…
Add table
Reference in a new issue