instructeurs: affiche l'effectif moyen annuel n-1
This commit is contained in:
parent
85d119fa4d
commit
453adf3c74
11 changed files with 94 additions and 3 deletions
|
@ -4,6 +4,7 @@ class ApiEntreprise::API
|
||||||
EXERCICES_RESOURCE_NAME = "exercices"
|
EXERCICES_RESOURCE_NAME = "exercices"
|
||||||
RNA_RESOURCE_NAME = "associations"
|
RNA_RESOURCE_NAME = "associations"
|
||||||
EFFECTIFS_RESOURCE_NAME = "effectifs_mensuels_acoss_covid"
|
EFFECTIFS_RESOURCE_NAME = "effectifs_mensuels_acoss_covid"
|
||||||
|
EFFECTIFS_ANNUELS_RESOURCE_NAME = "effectifs_annuels_acoss_covid"
|
||||||
|
|
||||||
TIMEOUT = 15
|
TIMEOUT = 15
|
||||||
|
|
||||||
|
@ -34,6 +35,10 @@ class ApiEntreprise::API
|
||||||
call(endpoint, siren, procedure_id)
|
call(endpoint, siren, procedure_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.effectifs_annuels(siren, procedure_id)
|
||||||
|
call(EFFECTIFS_ANNUELS_RESOURCE_NAME, 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)
|
||||||
|
|
23
app/lib/api_entreprise/effectifs_annuels_adapter.rb
Normal file
23
app/lib/api_entreprise/effectifs_annuels_adapter.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
class ApiEntreprise::EffectifsAnnuelsAdapter < ApiEntreprise::Adapter
|
||||||
|
def initialize(siren, procedure_id)
|
||||||
|
@siren = siren
|
||||||
|
@procedure_id = procedure_id
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_resource
|
||||||
|
ApiEntreprise::API.effectifs_annuels(@siren, @procedure_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_params
|
||||||
|
if data_source[:effectifs_annuels].present?
|
||||||
|
{
|
||||||
|
entreprise_effectif_annuel: data_source[:effectifs_annuels],
|
||||||
|
entreprise_effectif_annuel_annee: data_source[:annee]
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -29,6 +29,12 @@ class ApiEntrepriseService
|
||||||
rescue ApiEntreprise::API::RequestFailed
|
rescue ApiEntreprise::API::RequestFailed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
effectifs_annuels_params = ApiEntreprise::EffectifsAnnuelsAdapter.new(entreprise_params[:entreprise_siren], procedure_id).to_params
|
||||||
|
etablissement_params.merge!(effectifs_annuels_params)
|
||||||
|
rescue ApiEntreprise::API::RequestFailed
|
||||||
|
end
|
||||||
|
|
||||||
etablissement_params.merge(entreprise_params)
|
etablissement_params.merge(entreprise_params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,10 +35,15 @@
|
||||||
(URSSAF)
|
(URSSAF)
|
||||||
%td= etablissement.entreprise_effectif_mensuel
|
%td= etablissement.entreprise_effectif_mensuel
|
||||||
%tr
|
%tr
|
||||||
%th.libelle Effectif de l'organisation :
|
%th.libelle
|
||||||
|
Effectif moyen annuel
|
||||||
|
= etablissement.entreprise_effectif_annuel_annee
|
||||||
|
(URSSAF)
|
||||||
|
%td= etablissement.entreprise_effectif_annuel
|
||||||
|
%tr
|
||||||
|
%th.libelle Effectif de l'organisation (INSEE) :
|
||||||
%td
|
%td
|
||||||
= effectif(etablissement)
|
= effectif(etablissement)
|
||||||
(INSEE)
|
|
||||||
%tr
|
%tr
|
||||||
%th.libelle Numéro de TVA intracommunautaire :
|
%th.libelle Numéro de TVA intracommunautaire :
|
||||||
%td= etablissement.entreprise.numero_tva_intracommunautaire
|
%td= etablissement.entreprise.numero_tva_intracommunautaire
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddEffectifAnneeAnterieure < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :etablissements, :entreprise_effectif_annuel, :decimal
|
||||||
|
add_column :etablissements, :entreprise_effectif_annuel_annee, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_04_21_174642) do
|
ActiveRecord::Schema.define(version: 2020_04_22_090426) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -314,6 +314,8 @@ ActiveRecord::Schema.define(version: 2020_04_21_174642) do
|
||||||
t.string "entreprise_effectif_mois"
|
t.string "entreprise_effectif_mois"
|
||||||
t.string "entreprise_effectif_annee"
|
t.string "entreprise_effectif_annee"
|
||||||
t.decimal "entreprise_effectif_mensuel"
|
t.decimal "entreprise_effectif_mensuel"
|
||||||
|
t.decimal "entreprise_effectif_annuel"
|
||||||
|
t.string "entreprise_effectif_annuel_annee"
|
||||||
t.index ["dossier_id"], name: "index_etablissements_on_dossier_id"
|
t.index ["dossier_id"], name: "index_etablissements_on_dossier_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -212,6 +212,9 @@ describe Users::DossiersController, type: :controller do
|
||||||
let(:annee) { "2020" }
|
let(:annee) { "2020" }
|
||||||
let(:mois) { "02" }
|
let(:mois) { "02" }
|
||||||
|
|
||||||
|
let(:api_entreprise_effectifs_annuels_status) { 200 }
|
||||||
|
let(:api_entreprise_effectifs_annuels_body) { File.read('spec/fixtures/files/api_entreprise/effectifs_annuels.json') }
|
||||||
|
|
||||||
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') }
|
||||||
|
|
||||||
|
@ -229,6 +232,8 @@ describe Users::DossiersController, type: :controller do
|
||||||
.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=/)
|
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)
|
.to_return(body: api_entreprise_effectifs_mensuels_body, status: api_entreprise_effectifs_mensuels_status)
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
||||||
|
.to_return(body: api_entreprise_effectifs_annuels_body, status: api_entreprise_effectifs_annuels_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -328,6 +333,7 @@ describe Users::DossiersController, type: :controller do
|
||||||
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.entreprise_effectif_mensuel).to be_present
|
expect(dossier.etablissement.entreprise_effectif_mensuel).to be_present
|
||||||
|
expect(dossier.etablissement.entreprise_effectif_annuel).to be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,6 +76,8 @@ feature 'Creating a new dossier:' do
|
||||||
.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=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/2020\/02\/entreprise\/#{siren}?.*token=/)
|
||||||
.to_return(status: 404, body: '')
|
.to_return(status: 404, body: '')
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
||||||
|
.to_return(status: 404, body: '')
|
||||||
end
|
end
|
||||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
||||||
|
|
5
spec/fixtures/files/api_entreprise/effectifs_annuels.json
vendored
Normal file
5
spec/fixtures/files/api_entreprise/effectifs_annuels.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"siren": "418166096",
|
||||||
|
"annee": "2019",
|
||||||
|
"effectifs_annuels": 100.5
|
||||||
|
}
|
24
spec/lib/api_entreprise/effectifs_annuels_adapter_spec.rb
Normal file
24
spec/lib/api_entreprise/effectifs_annuels_adapter_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
describe ApiEntreprise::EffectifsAnnuelsAdapter do
|
||||||
|
let(:siren) { '418166096' }
|
||||||
|
let(:procedure_id) { 22 }
|
||||||
|
let(:adapter) { described_class.new(siren, procedure_id) }
|
||||||
|
subject { adapter.to_params }
|
||||||
|
|
||||||
|
before do
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{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_annuels.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 de l'année antérieure" do
|
||||||
|
expect(subject[:entreprise_effectif_annuel]).to eq(100.5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,6 +11,8 @@ describe ApiEntrepriseService do
|
||||||
.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=/)
|
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)
|
.to_return(body: effectifs_mensuels_body, status: effectifs_mensuels_status)
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
||||||
|
.to_return(body: effectifs_annuels_body, status: effectifs_annuels_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||||
|
@ -32,6 +34,10 @@ describe ApiEntrepriseService do
|
||||||
let(:mois) { "02" }
|
let(:mois) { "02" }
|
||||||
let(:effectif_mensuel) { 100.5 }
|
let(:effectif_mensuel) { 100.5 }
|
||||||
|
|
||||||
|
let(:effectifs_annuels_status) { 200 }
|
||||||
|
let(:effectifs_annuels_body) { File.read('spec/fixtures/files/api_entreprise/effectifs_annuels.json') }
|
||||||
|
let(:effectif_annuel) { 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') }
|
||||||
|
|
||||||
|
@ -47,6 +53,7 @@ describe ApiEntrepriseService do
|
||||||
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[:entreprise_effectif_mensuel]).to eq(effectif_mensuel)
|
expect(result[:entreprise_effectif_mensuel]).to eq(effectif_mensuel)
|
||||||
|
expect(result[:entreprise_effectif_annuel]).to eq(effectif_annuel)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue