fetch and show effectif mensuel
- fetch and store effectif mensuel (at the creation of the dossier or when updating a siret field - show effectif mensuel only for instructeurs
This commit is contained in:
parent
599d8e33e8
commit
db3ef195ad
8 changed files with 72 additions and 3 deletions
|
@ -130,6 +130,14 @@ module ApplicationHelper
|
|||
datetime.present? ? I18n.l(datetime) : ''
|
||||
end
|
||||
|
||||
def try_format_mois_effectif(etablissement)
|
||||
if etablissement.effectif_mois.present? && etablissement.effectif_annee.present?
|
||||
[etablissement.effectif_mois, etablissement.effectif_annee].join('/')
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
def dismiss_outdated_browser_banner
|
||||
cookies[:dismissed_outdated_browser_banner] = {
|
||||
value: 'true',
|
||||
|
|
|
@ -23,7 +23,27 @@ class ApiEntrepriseService
|
|||
rescue ApiEntreprise::API::RequestFailed
|
||||
end
|
||||
|
||||
begin
|
||||
effectifs_params = ApiEntreprise::EffectifsAdapter.new(entreprise_params[:entreprise_siren], procedure_id, *get_current_valid_month_for_effectif).to_params
|
||||
etablissement_params.merge!(effectifs_params)
|
||||
rescue ApiEntreprise::API::RequestFailed
|
||||
end
|
||||
|
||||
etablissement_params.merge(entreprise_params)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.get_current_valid_month_for_effectif
|
||||
today = Date.today
|
||||
date_update = Date.new(today.year, today.month, 15)
|
||||
|
||||
if today >= date_update
|
||||
[today.strftime("%Y"), today.strftime("%m")]
|
||||
else
|
||||
date = today - 1.month
|
||||
[date.strftime("%Y"), date.strftime("%m")]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,12 @@
|
|||
%tr
|
||||
%th.libelle Date de création :
|
||||
%td= try_format_date(etablissement.entreprise.date_creation)
|
||||
- if profile == 'instructeur'
|
||||
%tr
|
||||
%th.libelle
|
||||
Effectif mensuel
|
||||
= try_format_mois_effectif(etablissement)
|
||||
%td= etablissement.effectif_mensuel
|
||||
%tr
|
||||
%th.libelle Effectif de l'organisation :
|
||||
%td= effectif(etablissement)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class AddEffectifsMensuelsToEtablissements < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :etablissements, :effectif_mois, :string
|
||||
add_column :etablissements, :effectif_annee, :string
|
||||
add_column :etablissements, :effectif_mensuel, :decimal
|
||||
end
|
||||
end
|
|
@ -310,6 +310,9 @@ ActiveRecord::Schema.define(version: 2020_04_09_075320) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "diffusable_commercialement"
|
||||
t.string "effectif_mois"
|
||||
t.string "effectif_annee"
|
||||
t.decimal "effectif_mensuel"
|
||||
t.index ["dossier_id"], name: "index_etablissements_on_dossier_id"
|
||||
end
|
||||
|
||||
|
|
|
@ -207,6 +207,11 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:api_entreprise_status) { 200 }
|
||||
let(:api_entreprise_body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }
|
||||
|
||||
let(:api_entreprise_effectifs_mensuels_status) { 200 }
|
||||
let(:api_entreprise_effectifs_mensuels_body) { File.read('spec/fixtures/files/api_entreprise/effectifs.json') }
|
||||
let(:annee) { "2020" }
|
||||
let(:mois) { "02" }
|
||||
|
||||
let(:api_exercices_status) { 200 }
|
||||
let(:api_exercices_body) { File.read('spec/fixtures/files/api_entreprise/exercices.json') }
|
||||
|
||||
|
@ -222,12 +227,16 @@ describe Users::DossiersController, type: :controller do
|
|||
.to_return(status: api_exercices_status, body: api_exercices_body)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
|
||||
.to_return(status: api_association_status, body: api_association_body)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}?.*token=/)
|
||||
.to_return(body: api_entreprise_effectifs_mensuels_body, status: api_entreprise_effectifs_mensuels_status)
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
stub_api_entreprise_requests
|
||||
end
|
||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||
after { Timecop.return }
|
||||
|
||||
subject! { post :update_siret, params: { id: dossier.id, user: { siret: params_siret } } }
|
||||
|
||||
|
@ -266,8 +275,7 @@ describe Users::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'with a valid SIRET' do
|
||||
let(:params_siret) { '440 117 620 01530' }
|
||||
|
||||
let(:params_siret) { '418 166 096 00051' }
|
||||
context 'When API-Entreprise is down' do
|
||||
let(:api_etablissement_status) { 502 }
|
||||
let(:api_body_status) { File.read('spec/fixtures/files/api_entreprise/exercices_unavailable.json') }
|
||||
|
@ -319,6 +327,7 @@ describe Users::DossiersController, type: :controller do
|
|||
expect(dossier.etablissement.entreprise).to be_present
|
||||
expect(dossier.etablissement.exercices).to be_present
|
||||
expect(dossier.etablissement.association?).to be(true)
|
||||
expect(dossier.etablissement.effectif_mensuel).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
feature 'Creating a new dossier:' do
|
||||
let(:user) { create(:user) }
|
||||
let(:siret) { '40307130100044' }
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siren) { siret[0...9] }
|
||||
|
||||
context 'when the user is already signed in' do
|
||||
|
@ -74,7 +74,11 @@ feature 'Creating a new dossier:' do
|
|||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/exercices.json'))
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
|
||||
.to_return(status: 404, body: '')
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/2020\/02\/entreprise\/#{siren}?.*token=/)
|
||||
.to_return(status: 404, body: '')
|
||||
end
|
||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||
after { Timecop.return }
|
||||
|
||||
scenario 'the user can enter the SIRET of its etablissement and create a new draft' do
|
||||
visit commencer_path(path: procedure.path)
|
||||
|
|
|
@ -9,8 +9,13 @@ describe ApiEntrepriseService do
|
|||
.to_return(body: exercices_body, status: exercices_status)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/.*token=/)
|
||||
.to_return(body: associations_body, status: associations_status)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}?.*token=/)
|
||||
.to_return(body: effectifs_mensuels_body, status: effectifs_mensuels_status)
|
||||
end
|
||||
|
||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||
after { Timecop.return }
|
||||
|
||||
let(:siren) { '418166096' }
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:rna) { 'W595001988' }
|
||||
|
@ -21,6 +26,12 @@ describe ApiEntrepriseService do
|
|||
let(:etablissements_status) { 200 }
|
||||
let(:etablissements_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
||||
|
||||
let(:effectifs_mensuels_status) { 200 }
|
||||
let(:effectifs_mensuels_body) { File.read('spec/fixtures/files/api_entreprise/effectifs.json') }
|
||||
let(:annee) { "2020" }
|
||||
let(:mois) { "02" }
|
||||
let(:effectif_mensuel) { 100.5 }
|
||||
|
||||
let(:exercices_status) { 200 }
|
||||
let(:exercices_body) { File.read('spec/fixtures/files/api_entreprise/exercices.json') }
|
||||
|
||||
|
@ -35,6 +46,7 @@ describe ApiEntrepriseService do
|
|||
expect(result[:siret]).to eq(siret)
|
||||
expect(result[:association_rna]).to eq(rna)
|
||||
expect(result[:exercices_attributes]).to_not be_empty
|
||||
expect(result[:effectif_mensuel]).to eq(effectif_mensuel)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue