From 0f083db32bae8d79f826b78137d276b42e486b02 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Sun, 28 May 2023 13:10:18 +0200 Subject: [PATCH 1/3] migrate bilans bdf adapter to v3 --- app/lib/api_entreprise/api.rb | 2 +- app/lib/api_entreprise/bilans_bdf_adapter.rb | 18 ++- .../api_entreprise/bilans_entreprise_bdf.json | 120 +++++++++++------- .../api_entreprise/bilans_bdf_job_spec.rb | 4 +- .../api_entreprise/bilans_bdf_adapter_spec.rb | 4 +- 5 files changed, 88 insertions(+), 60 deletions(-) diff --git a/app/lib/api_entreprise/api.rb b/app/lib/api_entreprise/api.rb index 36f555a48..e6c686abf 100644 --- a/app/lib/api_entreprise/api.rb +++ b/app/lib/api_entreprise/api.rb @@ -9,7 +9,7 @@ class APIEntreprise::API EFFECTIFS_ANNUELS_RESOURCE_NAME = "v2/effectifs_annuels_acoss_covid/%{id}" ATTESTATION_SOCIALE_RESOURCE_NAME = "v4/urssaf/unites_legales/%{id}/attestation_vigilance" ATTESTATION_FISCALE_RESOURCE_NAME = "v4/dgfip/unites_legales/%{id}/attestation_fiscale" - BILANS_BDF_RESOURCE_NAME = "v2/bilans_entreprises_bdf/%{id}" + BILANS_BDF_RESOURCE_NAME = "v3/banque_de_france/unites_legales/%{id}/bilans" PRIVILEGES_RESOURCE_NAME = "v2/privileges" TIMEOUT = 20 diff --git a/app/lib/api_entreprise/bilans_bdf_adapter.rb b/app/lib/api_entreprise/bilans_bdf_adapter.rb index c50d689b6..6d05f2455 100644 --- a/app/lib/api_entreprise/bilans_bdf_adapter.rb +++ b/app/lib/api_entreprise/bilans_bdf_adapter.rb @@ -11,13 +11,17 @@ class APIEntreprise::BilansBdfAdapter < APIEntreprise::Adapter end def process_params - if data_source[:bilans].present? - { - entreprise_bilans_bdf: data_source[:bilans], - entreprise_bilans_bdf_monnaie: data_source[:monnaie] - } - else - {} + Sentry.with_scope do |scope| + data = data_source[:data] + scope.set_tags(siret: @siret) + scope.set_extras(source: data) + + result = {} + if data + result[:entreprise_bilans_bdf] = data + result[:entreprise_bilans_bdf_monnaie] = 'euros' + end + result end end end diff --git a/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json b/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json index 1f2350363..5b5640592 100644 --- a/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json +++ b/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json @@ -1,51 +1,75 @@ { - "monnaie": "kEuros", - "bilans": [ + "data": [ { - "duree_exercice": "12", - "valeur_ajoutee_bdf": "7848792", - "resultat_exercice": "347126", - "capitaux_propres_et_assimiles": "5928663", - "total_provisions_pour_risques_et_charges": "1957919", - "dettes1_emprunts_obligataires_et_convertibles": "0", - "dettes2_autres_emprunts_obligataires": "6552306", - "total_dettes_stables": "6552306", - "emprunts_et_dettes_financieres_divers": "430634", - "groupes_et_associes": "0", - "besoin_en_fonds_de_roulement": "-721507", - "disponibilites": "1983051", - "total_passif": "18478051", - "evolution_valeur_ajoutee_bdf": "", - "evolution_resultat_exercice": "", - "evolution_capitaux_propres_et_assimiles": "", - "evolution_total_provisions_pour_risques_et_charges": "", - "evolution_dettes1_emprunts_obligataires_et_convertibles": "", - "evolution_dettes2_autres_emprunts_obligataires": "", - "evolution_emprunts_et_dettes_financieres_divers": "", - "evolution_groupes_et_associes": "", - "evolution_besoin_en_fonds_de_roulement": "", - "evolution_disponibilites": "", - "evolution_total_passif": "", - "chiffre_affaires_ht": "12030700", - "capacite_autofinancement": "891914", - "date_arret_exercice": "201512", - "dettes3_emprunts_et_dettes_aupres_des_etablissements_de_credit": "0", - "dettes4_maturite_a_un_an_au_plus": "0", - "autres_fonds_propres": "0", - "capital_social_inclus_dans_capitaux_propres_et_assimiles": "3800000", - "excedent_brut_exploitation": "-1876863", - "evolution_chiffre_affaires_ht": "", - "evolution_capacite_autofinancement": "", - "evolution_dettes3_emprunts_et_dettes_aupres_des_etablissements_de_credit": "", - "evolution_dettes4_maturite_a_un_an_au_plus": "", - "evolution_autres_fonds_propres": "", - "evolution_capital_social_inclus_dans_capitaux_propres_et_assimiles": "", - "evolution_excedent_brut_exploitation": "", - "evolution_fonds_roulement_net_global": "", - "evolution_ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement": "", - "evolution_total_dettes_stables": "", - "fonds_roulement_net_global": "2464585", - "ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement": "-" - }, "bilan 2", "bilan 3" - ] + "data": { + "annee": "2020", + "date_arrete_exercice": "202012", + "valeurs_calculees": [ + { + "disponibilites": { + "valeur": "9001", + "evolution": 12.34 + }, + "total_dettes_stables": { + "valeur": "9001", + "evolution": 12.34 + }, + "valeur_ajoutee_bdf": { + "valeur": "9001", + "evolution": 12.34 + }, + "besoin_en_fonds_de_roulement": { + "valeur": "9001", + "evolution": 12.34 + }, + "excedent_brut_exploitation": { + "valeur": "9001", + "evolution": 12.34 + }, + "capacite_autofinancement": { + "valeur": "9001", + "evolution": 12.34 + }, + "fonds_roulement_net_global": { + "valeur": "9001", + "evolution": 12.34 + }, + "ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement": { + "valeur": 23.45, + "evolution": 12.34 + }, + "dettes4_maturite_a_un_an_au_plus": { + "valeur": "9001", + "evolution": 12.34 + } + } + ], + "declarations": [ + { + "numero_imprime": "2051", + "donnees": [ + { + "code": "GR", + "code_EDI": "GR:C889:7111:1:TBX", + "evolution": 4.56, + "code_absolu": "2006744", + "code_type_donnee": "CCI", + "intitule": "Déposé néant", + "code_nref": "304651", + "valeurs": [ + "dummy" + ] + } + ] + } + ] + }, + "links": {}, + "meta": {} + } + ], + "meta": { + "count": 1 + }, + "links": {} } diff --git a/spec/jobs/api_entreprise/bilans_bdf_job_spec.rb b/spec/jobs/api_entreprise/bilans_bdf_job_spec.rb index a3b0f60a0..d28dc38ad 100644 --- a/spec/jobs/api_entreprise/bilans_bdf_job_spec.rb +++ b/spec/jobs/api_entreprise/bilans_bdf_job_spec.rb @@ -6,10 +6,10 @@ RSpec.describe APIEntreprise::BilansBdfJob, type: :job do let(:procedure_id) { procedure.id } let(:body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') } let(:status) { 200 } - let(:bilans_bdf) { JSON.parse(body)["bilans"] } + let(:bilans_bdf) { JSON.parse(body)["data"] } before do - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) + stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/banque_de_france\/unites_legales\/#{siren}\/bilans/) .to_return(body: body, status: status) allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"]) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) diff --git a/spec/lib/api_entreprise/bilans_bdf_adapter_spec.rb b/spec/lib/api_entreprise/bilans_bdf_adapter_spec.rb index 7945d0cf0..4d5c0414f 100644 --- a/spec/lib/api_entreprise/bilans_bdf_adapter_spec.rb +++ b/spec/lib/api_entreprise/bilans_bdf_adapter_spec.rb @@ -7,7 +7,7 @@ describe APIEntreprise::BilansBdfAdapter do subject { adapter.to_params } before do - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) + stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/banque_de_france\/unites_legales\/#{siren}\/bilans/) .to_return(body: body, status: status) allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"]) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) @@ -22,7 +22,7 @@ describe APIEntreprise::BilansBdfAdapter do end it "returns bilans bdf" do - expect(subject[:entreprise_bilans_bdf][0][:valeur_ajoutee_bdf]).to eq("7848792") + expect(subject[:entreprise_bilans_bdf][0][:data][:valeurs_calculees][0][:excedent_brut_exploitation][:valeur]).to eq "9001" end end end From 42acc71cbe37e06d8a0f5d879c2cb8e7d70fa248 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Sun, 28 May 2023 17:09:43 +0200 Subject: [PATCH 2/3] display v2 and v3 bilans bdf --- app/helpers/etablissement_helper.rb | 15 ++++-- ...identite_entreprise_bilan_detail.html.haml | 2 +- .../bilans_entreprise_bdf_v2.json | 51 +++++++++++++++++++ .../_identite_entreprise.html.haml_spec.rb | 38 +++++++++++++- 4 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json diff --git a/app/helpers/etablissement_helper.rb b/app/helpers/etablissement_helper.rb index 502a16497..cd705bd6f 100644 --- a/app/helpers/etablissement_helper.rb +++ b/app/helpers/etablissement_helper.rb @@ -1,14 +1,23 @@ module EtablissementHelper + def value_for_bilan_key(bilan, key) + if bilan["data"] + return "NA" if key == "resultat_exercice" + bilan["data"][key].presence || bilan["data"]["valeurs_calculees"][0][key].present? ? bilan["data"]["valeurs_calculees"][0][key]["valeur"] : nil + else + bilan[key] + end + end + def pretty_siret(siret) "#{siret[0..2]} #{siret[3..5]} #{siret[6..8]} #{siret[9..]}" end - def pretty_currency(capital_social, unit: '€') - number_to_currency(capital_social, locale: :fr, unit: unit, precision: 0) + def pretty_currency(value, unit: '€') + number_to_currency(value, locale: :fr, unit: unit, precision: 0) end def pretty_currency_unit(unit) - dict = { 'kEuros' => 'k€' } + dict = { 'kEuros' => 'k€', 'euros' => '€' } dict[unit] end diff --git a/app/views/shared/dossiers/_identite_entreprise_bilan_detail.html.haml b/app/views/shared/dossiers/_identite_entreprise_bilan_detail.html.haml index f6cdf250e..2c48e126b 100644 --- a/app/views/shared/dossiers/_identite_entreprise_bilan_detail.html.haml +++ b/app/views/shared/dossiers/_identite_entreprise_bilan_detail.html.haml @@ -5,6 +5,6 @@ %details - etablissement.entreprise_bilans_bdf.each do |bilan| = "#{pretty_date_exercice(bilan["date_arret_exercice"])} : " - = pretty_currency(bilan[key], unit: pretty_currency_unit(etablissement.entreprise_bilans_bdf_monnaie)) + = pretty_currency(value_for_bilan_key(bilan, key), unit: pretty_currency_unit(etablissement.entreprise_bilans_bdf_monnaie)) %br diff --git a/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json b/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json new file mode 100644 index 000000000..1f2350363 --- /dev/null +++ b/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json @@ -0,0 +1,51 @@ +{ + "monnaie": "kEuros", + "bilans": [ + { + "duree_exercice": "12", + "valeur_ajoutee_bdf": "7848792", + "resultat_exercice": "347126", + "capitaux_propres_et_assimiles": "5928663", + "total_provisions_pour_risques_et_charges": "1957919", + "dettes1_emprunts_obligataires_et_convertibles": "0", + "dettes2_autres_emprunts_obligataires": "6552306", + "total_dettes_stables": "6552306", + "emprunts_et_dettes_financieres_divers": "430634", + "groupes_et_associes": "0", + "besoin_en_fonds_de_roulement": "-721507", + "disponibilites": "1983051", + "total_passif": "18478051", + "evolution_valeur_ajoutee_bdf": "", + "evolution_resultat_exercice": "", + "evolution_capitaux_propres_et_assimiles": "", + "evolution_total_provisions_pour_risques_et_charges": "", + "evolution_dettes1_emprunts_obligataires_et_convertibles": "", + "evolution_dettes2_autres_emprunts_obligataires": "", + "evolution_emprunts_et_dettes_financieres_divers": "", + "evolution_groupes_et_associes": "", + "evolution_besoin_en_fonds_de_roulement": "", + "evolution_disponibilites": "", + "evolution_total_passif": "", + "chiffre_affaires_ht": "12030700", + "capacite_autofinancement": "891914", + "date_arret_exercice": "201512", + "dettes3_emprunts_et_dettes_aupres_des_etablissements_de_credit": "0", + "dettes4_maturite_a_un_an_au_plus": "0", + "autres_fonds_propres": "0", + "capital_social_inclus_dans_capitaux_propres_et_assimiles": "3800000", + "excedent_brut_exploitation": "-1876863", + "evolution_chiffre_affaires_ht": "", + "evolution_capacite_autofinancement": "", + "evolution_dettes3_emprunts_et_dettes_aupres_des_etablissements_de_credit": "", + "evolution_dettes4_maturite_a_un_an_au_plus": "", + "evolution_autres_fonds_propres": "", + "evolution_capital_social_inclus_dans_capitaux_propres_et_assimiles": "", + "evolution_excedent_brut_exploitation": "", + "evolution_fonds_roulement_net_global": "", + "evolution_ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement": "", + "evolution_total_dettes_stables": "", + "fonds_roulement_net_global": "2464585", + "ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement": "-" + }, "bilan 2", "bilan 3" + ] +} diff --git a/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb b/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb index b20ccbfd2..2a3360c86 100644 --- a/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb @@ -1,13 +1,16 @@ describe 'shared/dossiers/identite_entreprise', type: :view do - before { render 'shared/dossiers/identite_entreprise', etablissement: etablissement, profile: 'usager' } + subject { render 'shared/dossiers/identite_entreprise', etablissement: etablissement, profile: profile } + let(:profile) { 'usager' } context "there is an association" do + let(:etablissement) { create(:etablissement, :is_association) } context "date_publication is missing on rna" do before { etablissement.update(association_date_publication: nil) } it "can render without error" do + subject expect(rendered).to include("Date de publication :") end end @@ -17,9 +20,42 @@ describe 'shared/dossiers/identite_entreprise', type: :view do let(:etablissement) { create(:etablissement, :non_diffusable, siret: "12345678900001") } it "hide any info except siret" do + subject expect(rendered).to have_text("123 456 789 00001") expect(rendered).not_to have_text(etablissement.entreprise_raison_sociale) expect(rendered).not_to have_text(etablissement.entreprise.forme_juridique) end end + + context 'for instructeur' do + let(:profile) { 'instructeur' } + + context 'with bilans bdf v2' do + let(:bilans) { JSON.parse(File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json')) } + let(:bilans_array) { bilans["bilans"] } + let(:bilans_monnaie) { bilans["monnaie"] } + let(:etablissement) { create(:etablissement, entreprise_bilans_bdf: bilans_array, entreprise_bilans_bdf_monnaie: bilans_monnaie, dossier: create(:dossier)) } + + it "can render without error" do + assign(:dossier, etablissement.dossier) + subject + expect(rendered).to include("Excédent brut d’exploitation") + expect(rendered).to include("-1 876 863 k€") + end + end + + context 'with bilans bdf v3' do + let(:bilans) { JSON.parse(File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json')) } + let(:bilans_array) { bilans["data"] } + let(:bilans_monnaie) { "euros" } + let(:etablissement) { create(:etablissement, entreprise_bilans_bdf: bilans_array, entreprise_bilans_bdf_monnaie: bilans_monnaie, dossier: create(:dossier)) } + + it "can render without error" do + assign(:dossier, etablissement.dossier) + subject + expect(rendered).to include("Excédent brut d’exploitation") + expect(rendered).to include("9 001") + end + end + end end From 50da50a7acbb14f246a5a44424439e13674a05a2 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 31 May 2023 16:07:04 +0200 Subject: [PATCH 3/3] amelioration(bilan_bdf.resultat_exercice): implement la logique d'affichage du resultat d'un exercice sur l'API v3 --- app/helpers/etablissement_helper.rb | 20 +- .../bilans_entreprise_bdf_v2.json | 2 +- .../bilans_entreprise_bdf_with_bilans.json | 628 ++++++++++++++++++ spec/helpers/etablissement_helper_spec.rb | 19 + spec/lib/api_entreprise/api_spec.rb | 2 +- .../_identite_entreprise.html.haml_spec.rb | 1 - 6 files changed, 667 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_with_bilans.json diff --git a/app/helpers/etablissement_helper.rb b/app/helpers/etablissement_helper.rb index cd705bd6f..6c95294d6 100644 --- a/app/helpers/etablissement_helper.rb +++ b/app/helpers/etablissement_helper.rb @@ -1,13 +1,29 @@ module EtablissementHelper def value_for_bilan_key(bilan, key) - if bilan["data"] - return "NA" if key == "resultat_exercice" + if bilan_v3?(bilan) + return extract_resultat_exercice(bilan['data']) if key == "resultat_exercice" bilan["data"][key].presence || bilan["data"]["valeurs_calculees"][0][key].present? ? bilan["data"]["valeurs_calculees"][0][key]["valeur"] : nil else bilan[key] end end + # trouver la declaration 2051, et prendre la premiere valeur du bilan identifié par le code code_nref: 300476 + # autrement connu comme le resultat d'un exercice dans un bilan comptable "funky magic accountant lingo" + def extract_resultat_exercice(bilan) + declaration_2051 = bilan.dig('declarations').find { _1["numero_imprime"] == "2051" } + return nil if declaration_2051.nil? + + total_general_data = declaration_2051.dig("donnees").find { _1["code_nref"] == "300476" } + return nil if total_general_data.nil? + + total_general_data.dig("valeurs", 0) + end + + def bilan_v3?(bilan) + bilan&.key?("data") + end + def pretty_siret(siret) "#{siret[0..2]} #{siret[3..5]} #{siret[6..8]} #{siret[9..]}" end diff --git a/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json b/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json index 1f2350363..5416840c5 100644 --- a/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json +++ b/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_v2.json @@ -46,6 +46,6 @@ "evolution_total_dettes_stables": "", "fonds_roulement_net_global": "2464585", "ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement": "-" - }, "bilan 2", "bilan 3" + } ] } diff --git a/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_with_bilans.json b/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_with_bilans.json new file mode 100644 index 000000000..95ddd8a82 --- /dev/null +++ b/spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_with_bilans.json @@ -0,0 +1,628 @@ +{ + "data":[ + { + "data":{ + "annee":"2022", + "date_arrete_exercice":"2022-08", + "declarations":[ + { + "numero_imprime":"2051", + "donnees":[ + { + "code_nref":"300476", + "valeurs":[ + "97065000" + ], + "evolution":55.85, + "code_absolu":"2000536", + "intitule":"Total général bilan passif n , exercice n total i + total ii + total iii + total iv + total v", + "code_EDI":"EE:C516:5004:1", + "code":"EE", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300438", + "valeurs":[ + "35042000" + ], + "evolution":50.71, + "code_absolu":"2000497", + "intitule":"Total (i) exercice n , total des capitaux propres n", + "code_EDI":"DL:C516:5004:1", + "code":"DL", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300414", + "valeurs":[ + "510000" + ], + "evolution":0.0, + "code_absolu":"2000472", + "intitule":"Capital social ou individuel n", + "code_EDI":"DA:C516:5004:1", + "code":"DA", + "code_type_donnee":"MOA" + }, + { + "code_nref":"302359", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2002767", + "intitule":"Total (iii) exercice n , total des provisions pour risques et charges n", + "code_EDI":"DR:C516:5004:1", + "code":"DR", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300451", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000511", + "intitule":"Emprunts obligataires convertibles n", + "code_EDI":"DS:C516:5004:1", + "code":"DS", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300453", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000513", + "intitule":"Autres emprunts obligataires n", + "code_EDI":"DT:C516:5004:1", + "code":"DT", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300455", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000515", + "intitule":"Emprunts et dettes auprès des établissements de crédit n", + "code_EDI":"DU:C516:5004:1", + "code":"DU", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300458", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000518", + "intitule":"Emprunts et dettes financières divers n", + "code_EDI":"DV:C516:5004:1", + "code":"DV", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2052", + "donnees":[ + { + "code_nref":"300506", + "valeurs":[ + "152238000" + ], + "evolution":18.7, + "code_absolu":"2000566", + "intitule":"Produits d'exploitation chiffre d'affaires net total", + "code_EDI":"FL:C516:5004:1", + "code":"FL", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2053", + "donnees":[ + { + "code_nref":"300606", + "valeurs":[ + "11790000" + ], + "evolution":26.56, + "code_absolu":"2000666", + "intitule":"5 - bénéfice ou perte (total des produits - total des charges)", + "code_EDI":"HN:C516:5004:1", + "code":"HN", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2057", + "donnees":[ + { + "code_nref":"301195", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2001265", + "intitule":"Dettes groupe, communauté d'exploitation et associés, montant brut", + "code_EDI":"VI:C516:5004:1", + "code":"VI", + "code_type_donnee":"MOA" + } + ] + } + ], + "valeurs_calculees":[ + { + "disponibilites":{ + "valeur":"1468000", + "evolution":376.62 + }, + "total_dettes_stables":{ + "valeur":"0", + "evolution":null + }, + "valeur_ajoutee_bdf":{ + "valeur":"102165000", + "evolution":15.82 + }, + "besoin_en_fonds_de_roulement":{ + "valeur":"-9703000", + "evolution":-151.08 + }, + "excedent_brut_exploitation":{ + "valeur":"18259000", + "evolution":22.87 + }, + "capacite_autofinancement":{ + "valeur":"10224000", + "evolution":-4.05 + }, + "fonds_roulement_net_global":{ + "valeur":"-8236000", + "evolution":-142.67 + }, + "ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement":{ + "valeur":0.0, + "evolution":null + }, + "dettes4_maturite_a_un_an_au_plus":{ + "valeur":"0", + "evolution":null + } + } + ] + }, + "links":{ + + }, + "meta":{ + + } + }, + { + "data":{ + "annee":"2021", + "date_arrete_exercice":"2021-08", + "declarations":[ + { + "numero_imprime":"2051", + "donnees":[ + { + "code_nref":"300476", + "valeurs":[ + "62283000" + ], + "evolution":25.39, + "code_absolu":"2000536", + "intitule":"Total général bilan passif n , exercice n total i + total ii + total iii + total iv + total v", + "code_EDI":"EE:C516:5004:1", + "code":"EE", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300438", + "valeurs":[ + "23252000" + ], + "evolution":26.94, + "code_absolu":"2000497", + "intitule":"Total (i) exercice n , total des capitaux propres n", + "code_EDI":"DL:C516:5004:1", + "code":"DL", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300414", + "valeurs":[ + "510000" + ], + "evolution":0.0, + "code_absolu":"2000472", + "intitule":"Capital social ou individuel n", + "code_EDI":"DA:C516:5004:1", + "code":"DA", + "code_type_donnee":"MOA" + }, + { + "code_nref":"302359", + "valeurs":[ + "1165000" + ], + "evolution":30.9, + "code_absolu":"2002767", + "intitule":"Total (iii) exercice n , total des provisions pour risques et charges n", + "code_EDI":"DR:C516:5004:1", + "code":"DR", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300451", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000511", + "intitule":"Emprunts obligataires convertibles n", + "code_EDI":"DS:C516:5004:1", + "code":"DS", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300453", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000513", + "intitule":"Autres emprunts obligataires n", + "code_EDI":"DT:C516:5004:1", + "code":"DT", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300455", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000515", + "intitule":"Emprunts et dettes auprès des établissements de crédit n", + "code_EDI":"DU:C516:5004:1", + "code":"DU", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300458", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000518", + "intitule":"Emprunts et dettes financières divers n", + "code_EDI":"DV:C516:5004:1", + "code":"DV", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2052", + "donnees":[ + { + "code_nref":"300506", + "valeurs":[ + "128252000" + ], + "evolution":24.09, + "code_absolu":"2000566", + "intitule":"Produits d'exploitation chiffre d'affaires net total", + "code_EDI":"FL:C516:5004:1", + "code":"FL", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2053", + "donnees":[ + { + "code_nref":"300606", + "valeurs":[ + "9316000" + ], + "evolution":167.32, + "code_absolu":"2000666", + "intitule":"5 - bénéfice ou perte (total des produits - total des charges)", + "code_EDI":"HN:C516:5004:1", + "code":"HN", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2057", + "donnees":[ + { + "code_nref":"301195", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2001265", + "intitule":"Dettes groupe, communauté d'exploitation et associés, montant brut", + "code_EDI":"VI:C516:5004:1", + "code":"VI", + "code_type_donnee":"MOA" + } + ] + } + ], + "valeurs_calculees":[ + { + "disponibilites":{ + "valeur":"308000", + "evolution":0.65 + }, + "total_dettes_stables":{ + "valeur":"0", + "evolution":null + }, + "valeur_ajoutee_bdf":{ + "valeur":"88210000", + "evolution":25.62 + }, + "besoin_en_fonds_de_roulement":{ + "valeur":"18995000", + "evolution":52.19 + }, + "excedent_brut_exploitation":{ + "valeur":"14860000", + "evolution":75.88 + }, + "capacite_autofinancement":{ + "valeur":"10656000", + "evolution":86.59 + }, + "fonds_roulement_net_global":{ + "valeur":"19303000", + "evolution":50.96 + }, + "ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement":{ + "valeur":101.62, + "evolution":-0.81 + }, + "dettes4_maturite_a_un_an_au_plus":{ + "valeur":"0", + "evolution":null + } + } + ] + }, + "links":{ + + }, + "meta":{ + + } + }, + { + "data":{ + "annee":"2020", + "date_arrete_exercice":"2020-08", + "declarations":[ + { + "numero_imprime":"2051", + "donnees":[ + { + "code_nref":"300476", + "valeurs":[ + "49672000" + ], + "evolution":null, + "code_absolu":"2000536", + "intitule":"Total général bilan passif n , exercice n total i + total ii + total iii + total iv + total v", + "code_EDI":"EE:C516:5004:1", + "code":"EE", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300438", + "valeurs":[ + "18318000" + ], + "evolution":null, + "code_absolu":"2000497", + "intitule":"Total (i) exercice n , total des capitaux propres n", + "code_EDI":"DL:C516:5004:1", + "code":"DL", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300414", + "valeurs":[ + "510000" + ], + "evolution":null, + "code_absolu":"2000472", + "intitule":"Capital social ou individuel n", + "code_EDI":"DA:C516:5004:1", + "code":"DA", + "code_type_donnee":"MOA" + }, + { + "code_nref":"302359", + "valeurs":[ + "890000" + ], + "evolution":null, + "code_absolu":"2002767", + "intitule":"Total (iii) exercice n , total des provisions pour risques et charges n", + "code_EDI":"DR:C516:5004:1", + "code":"DR", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300451", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000511", + "intitule":"Emprunts obligataires convertibles n", + "code_EDI":"DS:C516:5004:1", + "code":"DS", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300453", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000513", + "intitule":"Autres emprunts obligataires n", + "code_EDI":"DT:C516:5004:1", + "code":"DT", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300455", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000515", + "intitule":"Emprunts et dettes auprès des établissements de crédit n", + "code_EDI":"DU:C516:5004:1", + "code":"DU", + "code_type_donnee":"MOA" + }, + { + "code_nref":"300458", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2000518", + "intitule":"Emprunts et dettes financières divers n", + "code_EDI":"DV:C516:5004:1", + "code":"DV", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2052", + "donnees":[ + { + "code_nref":"300506", + "valeurs":[ + "103357000" + ], + "evolution":null, + "code_absolu":"2000566", + "intitule":"Produits d'exploitation chiffre d'affaires net total", + "code_EDI":"FL:C516:5004:1", + "code":"FL", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2053", + "donnees":[ + { + "code_nref":"300606", + "valeurs":[ + "3485000" + ], + "evolution":null, + "code_absolu":"2000666", + "intitule":"5 - bénéfice ou perte (total des produits - total des charges)", + "code_EDI":"HN:C516:5004:1", + "code":"HN", + "code_type_donnee":"MOA" + } + ] + }, + { + "numero_imprime":"2057", + "donnees":[ + { + "code_nref":"301195", + "valeurs":[ + "0" + ], + "evolution":null, + "code_absolu":"2001265", + "intitule":"Dettes groupe, communauté d'exploitation et associés, montant brut", + "code_EDI":"VI:C516:5004:1", + "code":"VI", + "code_type_donnee":"MOA" + } + ] + } + ], + "valeurs_calculees":[ + { + "disponibilites":{ + "valeur":"306000", + "evolution":null + }, + "total_dettes_stables":{ + "valeur":"0", + "evolution":null + }, + "valeur_ajoutee_bdf":{ + "valeur":"70217000", + "evolution":null + }, + "besoin_en_fonds_de_roulement":{ + "valeur":"12481000", + "evolution":null + }, + "excedent_brut_exploitation":{ + "valeur":"8449000", + "evolution":null + }, + "capacite_autofinancement":{ + "valeur":"5711000", + "evolution":null + }, + "fonds_roulement_net_global":{ + "valeur":"12787000", + "evolution":null + }, + "ratio_fonds_roulement_net_global_sur_besoin_en_fonds_de_roulement":{ + "valeur":102.45, + "evolution":null + }, + "dettes4_maturite_a_un_an_au_plus":{ + "valeur":"0", + "evolution":null + } + } + ] + }, + "links":{ + + }, + "meta":{ + + } + } + ], + "meta":{ + "count":3 + }, + "links":{ + + } +} diff --git a/spec/helpers/etablissement_helper_spec.rb b/spec/helpers/etablissement_helper_spec.rb index d17c071ae..bb1248b95 100644 --- a/spec/helpers/etablissement_helper_spec.rb +++ b/spec/helpers/etablissement_helper_spec.rb @@ -24,6 +24,25 @@ RSpec.describe EtablissementHelper, type: :helper do it { is_expected.to eq("123 456 789 00001") } end + describe "#extract_resultat_exercice" do + let(:bilan) { bilans.first } + context 'having results' do + let(:bilans) { JSON.parse(File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf_with_bilans.json'))["data"] } + + it 'find value' do + expect(extract_resultat_exercice(bilan["data"])).to eq("97065000") + end + end + + context 'without results' do + let(:bilans) { JSON.parse(File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json'))["data"] } + + it 'does not crash' do + expect(extract_resultat_exercice(bilan["data"])).to eq(nil) + end + end + end + describe '#raison_sociale_or_name' do subject { raison_sociale_or_name(etablissement) } diff --git a/spec/lib/api_entreprise/api_spec.rb b/spec/lib/api_entreprise/api_spec.rb index 21c9e1a21..e74017b9b 100644 --- a/spec/lib/api_entreprise/api_spec.rb +++ b/spec/lib/api_entreprise/api_spec.rb @@ -239,7 +239,7 @@ describe APIEntreprise::API do before do allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(roles) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) + stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/banque_de_france\/unites_legales\/#{siren}\/bilans/) .to_return(body: body, status: status) end diff --git a/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb b/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb index 2a3360c86..845bf5d94 100644 --- a/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_identite_entreprise.html.haml_spec.rb @@ -3,7 +3,6 @@ describe 'shared/dossiers/identite_entreprise', type: :view do let(:profile) { 'usager' } context "there is an association" do - let(:etablissement) { create(:etablissement, :is_association) } context "date_publication is missing on rna" do