Merge pull request #9100 from demarches-simplifiees/8472-bilans-bdf

API Entreprise : migration "bilans bdf"
This commit is contained in:
mfo 2023-06-01 13:17:54 +00:00 committed by GitHub
commit a69cf8b7d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 852 additions and 66 deletions

View file

@ -1,14 +1,39 @@
module EtablissementHelper
def value_for_bilan_key(bilan, key)
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
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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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": {}
}

View file

@ -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": "-"
}
]
}

View file

@ -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":{
}
}

View file

@ -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) }

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,6 @@
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) }
@ -8,6 +9,7 @@ describe 'shared/dossiers/identite_entreprise', type: :view 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 +19,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 dexploitation")
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 dexploitation")
expect(rendered).to include("9 001")
end
end
end
end