doesn't update dossier etablissement for siret controller
This commit is contained in:
parent
b8093962ec
commit
fb87a09c02
4 changed files with 13 additions and 8 deletions
|
@ -50,7 +50,7 @@ class Champs::SiretController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_etablissement_with_siret
|
def find_etablissement_with_siret
|
||||||
ApiEntrepriseService.create_etablissement(@champ.dossier, @siret, current_user.id)
|
ApiEntrepriseService.create_etablissement(@champ, @siret, current_user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_siret_and_etablissement
|
def clear_siret_and_etablissement
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Champ < ApplicationRecord
|
||||||
belongs_to :etablissement, dependent: :destroy
|
belongs_to :etablissement, dependent: :destroy
|
||||||
has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
||||||
|
|
||||||
delegate :libelle, :type_champ, :order_place, :mandatory?, :description, :drop_down_list, :exclude_from_export?, :exclude_from_view?, :repetition?, :dossier_link?, to: :type_de_champ
|
delegate :libelle, :type_champ, :procedure, :order_place, :mandatory?, :description, :drop_down_list, :exclude_from_export?, :exclude_from_view?, :repetition?, :dossier_link?, to: :type_de_champ
|
||||||
|
|
||||||
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
||||||
scope :public_only, -> { where(private: false) }
|
scope :public_only, -> { where(private: false) }
|
||||||
|
|
|
@ -7,11 +7,11 @@ class ApiEntrepriseService
|
||||||
#
|
#
|
||||||
# Raises a ApiEntreprise::API::RequestFailed exception on transient errors
|
# Raises a ApiEntreprise::API::RequestFailed exception on transient errors
|
||||||
# (timeout, 5XX HTTP error code, etc.)
|
# (timeout, 5XX HTTP error code, etc.)
|
||||||
def self.create_etablissement(dossier, siret, user_id = nil)
|
def self.create_etablissement(dossier_or_champ, siret, user_id = nil)
|
||||||
etablissement_params = ApiEntreprise::EtablissementAdapter.new(siret, dossier.procedure.id).to_params
|
etablissement_params = ApiEntreprise::EtablissementAdapter.new(siret, dossier_or_champ.procedure.id).to_params
|
||||||
return nil if etablissement_params.empty?
|
return nil if etablissement_params.empty?
|
||||||
|
|
||||||
etablissement = dossier.build_etablissement(etablissement_params)
|
etablissement = dossier_or_champ.build_etablissement(etablissement_params)
|
||||||
etablissement.save
|
etablissement.save
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -19,9 +19,9 @@ class ApiEntrepriseService
|
||||||
ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob,
|
ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob,
|
||||||
ApiEntreprise::BilansBdfJob
|
ApiEntreprise::BilansBdfJob
|
||||||
].each do |job|
|
].each do |job|
|
||||||
job.perform_later(etablissement.id, dossier.procedure.id)
|
job.perform_later(etablissement.id, dossier_or_champ.procedure.id)
|
||||||
end
|
end
|
||||||
ApiEntreprise::AttestationFiscaleJob.perform_later(etablissement.id, dossier.procedure.id, user_id)
|
ApiEntreprise::AttestationFiscaleJob.perform_later(etablissement.id, dossier_or_champ.procedure.id, user_id)
|
||||||
|
|
||||||
etablissement
|
etablissement
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,11 @@ describe Champs::SiretController, type: :controller do
|
||||||
|
|
||||||
describe '#show' do
|
describe '#show' do
|
||||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||||
let(:champ) { create(:champ_siret, dossier: dossier, value: nil, etablissement: nil) }
|
let(:champ) do
|
||||||
|
d = dossier
|
||||||
|
type_de_champ = create(:type_de_champ_siret, procedure: procedure)
|
||||||
|
type_de_champ.champ.create(dossier: d, value: nil, etablissement: nil)
|
||||||
|
end
|
||||||
let(:params) do
|
let(:params) do
|
||||||
{
|
{
|
||||||
champ_id: champ.id,
|
champ_id: champ.id,
|
||||||
|
@ -109,6 +113,7 @@ describe Champs::SiretController, type: :controller do
|
||||||
expect(champ.value).to eq(siret)
|
expect(champ.value).to eq(siret)
|
||||||
expect(champ.etablissement.siret).to eq(siret)
|
expect(champ.etablissement.siret).to eq(siret)
|
||||||
expect(champ.reload.etablissement.naf).to eq("6202A")
|
expect(champ.reload.etablissement.naf).to eq("6202A")
|
||||||
|
expect(dossier.reload.etablissement).to eq(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue