Merge pull request #5038 from betagouv/4999-afficher-effectifs
4999 affiche pour les instructeurs les effectifs mensuels de l'entreprise
This commit is contained in:
commit
ea37d8ee0a
12 changed files with 136 additions and 3 deletions
|
@ -130,6 +130,14 @@ module ApplicationHelper
|
||||||
datetime.present? ? I18n.l(datetime) : ''
|
datetime.present? ? I18n.l(datetime) : ''
|
||||||
end
|
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
|
def dismiss_outdated_browser_banner
|
||||||
cookies[:dismissed_outdated_browser_banner] = {
|
cookies[:dismissed_outdated_browser_banner] = {
|
||||||
value: 'true',
|
value: 'true',
|
||||||
|
|
|
@ -3,6 +3,7 @@ class ApiEntreprise::API
|
||||||
ETABLISSEMENT_RESOURCE_NAME = "etablissements"
|
ETABLISSEMENT_RESOURCE_NAME = "etablissements"
|
||||||
EXERCICES_RESOURCE_NAME = "exercices"
|
EXERCICES_RESOURCE_NAME = "exercices"
|
||||||
RNA_RESOURCE_NAME = "associations"
|
RNA_RESOURCE_NAME = "associations"
|
||||||
|
EFFECTIFS_RESOURCE_NAME = "effectifs_mensuels_acoss_covid"
|
||||||
|
|
||||||
TIMEOUT = 15
|
TIMEOUT = 15
|
||||||
|
|
||||||
|
@ -28,6 +29,11 @@ class ApiEntreprise::API
|
||||||
call(RNA_RESOURCE_NAME, siret, procedure_id)
|
call(RNA_RESOURCE_NAME, siret, procedure_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.effectifs(siren, procedure_id, annee, mois)
|
||||||
|
endpoint = [EFFECTIFS_RESOURCE_NAME, annee, mois, "entreprise"].join('/')
|
||||||
|
call(endpoint, siren, procedure_id)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.call(resource_name, siret_or_siren, procedure_id)
|
def self.call(resource_name, siret_or_siren, procedure_id)
|
||||||
|
|
26
app/lib/api_entreprise/effectifs_adapter.rb
Normal file
26
app/lib/api_entreprise/effectifs_adapter.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter
|
||||||
|
def initialize(siren, procedure_id, annee, mois)
|
||||||
|
@siren = siren
|
||||||
|
@procedure_id = procedure_id
|
||||||
|
@annee = annee
|
||||||
|
@mois = mois
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_resource
|
||||||
|
ApiEntreprise::API.effectifs(@siren, @procedure_id, @annee, @mois)
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_params
|
||||||
|
if data_source[:effectifs_mensuels].present?
|
||||||
|
{
|
||||||
|
effectif_mensuel: data_source[:effectifs_mensuels],
|
||||||
|
effectif_mois: @mois,
|
||||||
|
effectif_annee: @annee
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -23,7 +23,27 @@ class ApiEntrepriseService
|
||||||
rescue ApiEntreprise::API::RequestFailed
|
rescue ApiEntreprise::API::RequestFailed
|
||||||
end
|
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)
|
etablissement_params.merge(entreprise_params)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -27,6 +27,12 @@
|
||||||
%tr
|
%tr
|
||||||
%th.libelle Date de création :
|
%th.libelle Date de création :
|
||||||
%td= try_format_date(etablissement.entreprise.date_creation)
|
%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
|
%tr
|
||||||
%th.libelle Effectif de l'organisation :
|
%th.libelle Effectif de l'organisation :
|
||||||
%td= effectif(etablissement)
|
%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 "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.boolean "diffusable_commercialement"
|
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"
|
t.index ["dossier_id"], name: "index_etablissements_on_dossier_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,11 @@ describe Users::DossiersController, type: :controller do
|
||||||
let(:api_entreprise_status) { 200 }
|
let(:api_entreprise_status) { 200 }
|
||||||
let(:api_entreprise_body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }
|
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_status) { 200 }
|
||||||
let(:api_exercices_body) { File.read('spec/fixtures/files/api_entreprise/exercices.json') }
|
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)
|
.to_return(status: api_exercices_status, body: api_exercices_body)
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
|
||||||
.to_return(status: api_association_status, body: api_association_body)
|
.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
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
stub_api_entreprise_requests
|
stub_api_entreprise_requests
|
||||||
end
|
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 } } }
|
subject! { post :update_siret, params: { id: dossier.id, user: { siret: params_siret } } }
|
||||||
|
|
||||||
|
@ -266,8 +275,7 @@ describe Users::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a valid SIRET' do
|
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
|
context 'When API-Entreprise is down' do
|
||||||
let(:api_etablissement_status) { 502 }
|
let(:api_etablissement_status) { 502 }
|
||||||
let(:api_body_status) { File.read('spec/fixtures/files/api_entreprise/exercices_unavailable.json') }
|
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.entreprise).to be_present
|
||||||
expect(dossier.etablissement.exercices).to be_present
|
expect(dossier.etablissement.exercices).to be_present
|
||||||
expect(dossier.etablissement.association?).to be(true)
|
expect(dossier.etablissement.association?).to be(true)
|
||||||
|
expect(dossier.etablissement.effectif_mensuel).to be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
feature 'Creating a new dossier:' do
|
feature 'Creating a new dossier:' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:siret) { '40307130100044' }
|
let(:siret) { '41816609600051' }
|
||||||
let(:siren) { siret[0...9] }
|
let(:siren) { siret[0...9] }
|
||||||
|
|
||||||
context 'when the user is already signed in' do
|
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'))
|
.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=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
|
||||||
.to_return(status: 404, body: '')
|
.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
|
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
|
scenario 'the user can enter the SIRET of its etablissement and create a new draft' do
|
||||||
visit commencer_path(path: procedure.path)
|
visit commencer_path(path: procedure.path)
|
||||||
|
|
6
spec/fixtures/files/api_entreprise/effectifs.json
vendored
Normal file
6
spec/fixtures/files/api_entreprise/effectifs.json
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"siren": "418166096",
|
||||||
|
"annee": "2020",
|
||||||
|
"mois": "02",
|
||||||
|
"effectifs_mensuels": 100.5
|
||||||
|
}
|
26
spec/lib/api_entreprise/effectifs_adapter_spec.rb
Normal file
26
spec/lib/api_entreprise/effectifs_adapter_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
describe ApiEntreprise::EffectifsAdapter do
|
||||||
|
let(:siren) { '418166096' }
|
||||||
|
let(:procedure_id) { 22 }
|
||||||
|
let(:annee) { "2020" }
|
||||||
|
let(:mois) { "02" }
|
||||||
|
let(:adapter) { described_class.new(siren, procedure_id, annee, mois) }
|
||||||
|
subject { adapter.to_params }
|
||||||
|
|
||||||
|
before do
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}?.*token=/)
|
||||||
|
.to_return(body: body, status: status)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the SIREN is valid" do
|
||||||
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/effectifs.json') }
|
||||||
|
let(:status) { 200 }
|
||||||
|
|
||||||
|
it '#to_params class est une Hash ?' do
|
||||||
|
expect(subject).to be_an_instance_of(Hash)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renvoie les effectifs du mois demandé" do
|
||||||
|
expect(subject[:effectif_mensuel]).to eq(100.5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,8 +9,13 @@ describe ApiEntrepriseService do
|
||||||
.to_return(body: exercices_body, status: exercices_status)
|
.to_return(body: exercices_body, status: exercices_status)
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/.*token=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/.*token=/)
|
||||||
.to_return(body: associations_body, status: associations_status)
|
.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
|
end
|
||||||
|
|
||||||
|
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||||
|
after { Timecop.return }
|
||||||
|
|
||||||
let(:siren) { '418166096' }
|
let(:siren) { '418166096' }
|
||||||
let(:siret) { '41816609600051' }
|
let(:siret) { '41816609600051' }
|
||||||
let(:rna) { 'W595001988' }
|
let(:rna) { 'W595001988' }
|
||||||
|
@ -21,6 +26,12 @@ describe ApiEntrepriseService do
|
||||||
let(:etablissements_status) { 200 }
|
let(:etablissements_status) { 200 }
|
||||||
let(:etablissements_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
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_status) { 200 }
|
||||||
let(:exercices_body) { File.read('spec/fixtures/files/api_entreprise/exercices.json') }
|
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[:siret]).to eq(siret)
|
||||||
expect(result[:association_rna]).to eq(rna)
|
expect(result[:association_rna]).to eq(rna)
|
||||||
expect(result[:exercices_attributes]).to_not be_empty
|
expect(result[:exercices_attributes]).to_not be_empty
|
||||||
|
expect(result[:effectif_mensuel]).to eq(effectif_mensuel)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue