Merge pull request #1572 from tchak/fix-siret-etablisement

Ensure only one entreprise is created for an etablissement
This commit is contained in:
Mathieu Magnin 2018-03-08 10:45:46 +01:00 committed by GitHub
commit 3c9c67c883
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 6 deletions

View file

@ -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)

View file

@ -181,7 +181,6 @@ class Dossier < ApplicationRecord
def reset!
etablissement.destroy
entreprise.destroy
update_columns(autorisation_donnees: false)
end

View file

@ -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

View file

@ -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