Merge pull request #1572 from tchak/fix-siret-etablisement
Ensure only one entreprise is created for an etablissement
This commit is contained in:
commit
3c9c67c883
4 changed files with 5 additions and 6 deletions
|
@ -110,7 +110,7 @@ class Users::DossiersController < UsersController
|
|||
|
||||
if etablissement_attributes.present?
|
||||
etablissement_attributes = ActionController::Parameters.new(etablissement_attributes).permit!
|
||||
etablissement = @facade.dossier.create_etablissement(etablissement_attributes)
|
||||
etablissement = @facade.dossier.build_etablissement(etablissement_attributes)
|
||||
if etablissement.save
|
||||
Rails.logger.info("etablissement saved, siret: #{siret}, id: #{etablissement.id}")
|
||||
@facade.dossier.mandataire_social!(current_user.france_connect_information)
|
||||
|
|
|
@ -181,7 +181,6 @@ class Dossier < ApplicationRecord
|
|||
|
||||
def reset!
|
||||
etablissement.destroy
|
||||
entreprise.destroy
|
||||
|
||||
update_columns(autorisation_donnees: false)
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class Entreprise < ApplicationRecord
|
||||
belongs_to :dossier
|
||||
has_one :etablissement, dependent: :destroy
|
||||
has_one :etablissement
|
||||
has_one :rna_information, dependent: :destroy
|
||||
|
||||
validates :siren, presence: true
|
||||
validates :dossier_id, uniqueness: true
|
||||
|
||||
accepts_nested_attributes_for :rna_information
|
||||
accepts_nested_attributes_for :rna_information, update_only: true
|
||||
|
||||
before_save :default_values
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class Etablissement < ApplicationRecord
|
||||
belongs_to :dossier
|
||||
belongs_to :entreprise
|
||||
belongs_to :entreprise, dependent: :destroy
|
||||
|
||||
has_many :exercices, dependent: :destroy
|
||||
|
||||
accepts_nested_attributes_for :exercices
|
||||
accepts_nested_attributes_for :entreprise
|
||||
accepts_nested_attributes_for :entreprise, update_only: true
|
||||
|
||||
validates :dossier_id, uniqueness: true
|
||||
|
||||
|
|
Loading…
Reference in a new issue