Merge pull request #10801 from tchak/api-entreprise-get-foreign-address
fix(api-entreprise): save libelle_commune_etranger and libelle_pays_etranger in db
This commit is contained in:
commit
ae7971bdea
8 changed files with 135 additions and 6 deletions
|
@ -25,7 +25,12 @@ class APIEntreprise::EtablissementAdapter < APIEntreprise::Adapter
|
|||
params.merge!(params[:adresse].slice(*address_attr_to_fetch))
|
||||
params[:nom_voie] = raw_data[:adresse][:libelle_voie]
|
||||
params[:code_insee_localite] = raw_data[:adresse][:code_commune]
|
||||
params[:localite] = raw_data[:adresse][:libelle_commune]
|
||||
if raw_data[:adresse][:libelle_pays_etranger].present?
|
||||
params[:localite] = raw_data[:adresse][:libelle_commune_etranger]
|
||||
params[:nom_pays] = raw_data[:adresse][:libelle_pays_etranger]
|
||||
else
|
||||
params[:localite] = raw_data[:adresse][:libelle_commune]
|
||||
end
|
||||
params[:adresse] = adresse_line
|
||||
params
|
||||
else
|
||||
|
|
|
@ -52,7 +52,8 @@ class Etablissement < ApplicationRecord
|
|||
adresse,
|
||||
code_postal,
|
||||
localite,
|
||||
code_insee_localite
|
||||
code_insee_localite,
|
||||
nom_pays
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNomPaysToEtablissements < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :etablissements, :nom_pays, :string
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_08_30_125438) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_09_13_150318) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_buffercache"
|
||||
enable_extension "pg_stat_statements"
|
||||
|
@ -570,6 +570,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_08_30_125438) do
|
|||
t.string "libelle_naf"
|
||||
t.string "localite"
|
||||
t.string "naf"
|
||||
t.string "nom_pays"
|
||||
t.string "nom_voie"
|
||||
t.string "numero_voie"
|
||||
t.boolean "siege_social"
|
||||
|
|
99
spec/fixtures/files/api_entreprise/etablissements-uk.json
vendored
Normal file
99
spec/fixtures/files/api_entreprise/etablissements-uk.json
vendored
Normal file
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"data": {
|
||||
"siret": "30613890001294",
|
||||
"siege_social": true,
|
||||
"etat_administratif": "A",
|
||||
"date_fermeture": 1634133818,
|
||||
"activite_principale": {
|
||||
"code": "8411Z",
|
||||
"libelle": "Administration publique générale",
|
||||
"nomenclature": "NAFRev2"
|
||||
},
|
||||
"tranche_effectif_salarie": {
|
||||
"code": "51",
|
||||
"intitule": "2 000 à 4 999 salariés",
|
||||
"date_reference": "2016",
|
||||
"de": 2000,
|
||||
"a": 4999
|
||||
},
|
||||
"status_diffusion": "diffusible",
|
||||
"diffusable_commercialement": true,
|
||||
"enseigne": "Coiff Land, CoiffureLand",
|
||||
"unite_legale": {
|
||||
"siren": "130025265",
|
||||
"siret_siege_social": "13002526500013",
|
||||
"type": "personne_morale",
|
||||
"personne_morale_attributs": {
|
||||
"raison_sociale": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
|
||||
"sigle": "DINUM"
|
||||
},
|
||||
"personne_physique_attributs": {
|
||||
"pseudonyme": "DJ Falcon",
|
||||
"prenom_usuel": "Jean",
|
||||
"prenom_1": "Jean",
|
||||
"prenom_2": "Jacques",
|
||||
"prenom_3": "Pierre",
|
||||
"prenom_4": "Paul",
|
||||
"nom_usage": "Dupont",
|
||||
"nom_naissance": "Martin",
|
||||
"sexe": "M"
|
||||
},
|
||||
"categorie_entreprise": "GE",
|
||||
"status_diffusion": "diffusible",
|
||||
"diffusable_commercialement": true,
|
||||
"forme_juridique": {
|
||||
"code": "7120",
|
||||
"libelle": "Service central d'un ministère"
|
||||
},
|
||||
"activite_principale": {
|
||||
"code": "8411Z",
|
||||
"libelle": "Administration publique générale",
|
||||
"nomenclature": "NAFRev2"
|
||||
},
|
||||
"tranche_effectif_salarie": {
|
||||
"code": "51",
|
||||
"intitule": "2 000 à 4 999 salariés",
|
||||
"date_reference": "2016",
|
||||
"de": 2000,
|
||||
"a": 4999
|
||||
},
|
||||
"etat_administratif": "A",
|
||||
"economie_sociale_et_solidaire": true,
|
||||
"date_creation": 1634103818
|
||||
},
|
||||
"adresse": {
|
||||
"numero_voie": "22",
|
||||
"indice_repetition_voie": "bis",
|
||||
"type_voie": "RUE",
|
||||
"libelle_voie": "DE LA PAIX",
|
||||
"complement_adresse": "ZAE SAINT GUENAULT",
|
||||
"code_commune": "75112",
|
||||
"code_postal": "75016",
|
||||
"distribution_speciale": "string",
|
||||
"code_cedex": "75590",
|
||||
"libelle_cedex": "PARIS CEDEX 12",
|
||||
"libelle_commune": null,
|
||||
"libelle_commune_etranger": "LONDRES",
|
||||
"code_pays_etranger": "99132",
|
||||
"libelle_pays_etranger": "ROYAUME-UNI",
|
||||
"status_diffusion": "diffusible",
|
||||
"acheminement_postal": {
|
||||
"l1": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
|
||||
"l2": "JEAN MARIE DURAND",
|
||||
"l3": "ZAE SAINT GUENAULT",
|
||||
"l4": "51 BIS RUE DE LA PAIX",
|
||||
"l5": "CS 72809",
|
||||
"l6": "75256 PARIX CEDEX 12",
|
||||
"l7": "FRANCE"
|
||||
}
|
||||
},
|
||||
"date_creation": 1634103818
|
||||
},
|
||||
"links": {
|
||||
"unite_legale": "https://entreprise.api.gouv.fr/api/v3/insee/unites_legales/130025265"
|
||||
},
|
||||
"meta": {
|
||||
"date_derniere_mise_a_jour": 1618396818,
|
||||
"redirect_from_siret": "30613890000010"
|
||||
}
|
||||
}
|
|
@ -73,9 +73,9 @@
|
|||
"code_cedex": "75590",
|
||||
"libelle_cedex": "PARIS CEDEX 12",
|
||||
"libelle_commune": "PARIS 12",
|
||||
"libelle_commune_etranger": "string",
|
||||
"libelle_commune_etranger": null,
|
||||
"code_pays_etranger": "99132",
|
||||
"libelle_pays_etranger": "ROYAUME-UNI",
|
||||
"libelle_pays_etranger": null,
|
||||
"status_diffusion": "diffusible",
|
||||
"acheminement_postal": {
|
||||
"l1": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
|
||||
|
|
|
@ -74,10 +74,26 @@ describe APIEntreprise::EtablissementAdapter do
|
|||
expect(subject[:localite]).to eq('PARIS 12')
|
||||
end
|
||||
|
||||
it 'L\'entreprise ne contient pas de nom de pays' do
|
||||
expect(subject[:nom_pays]).to be_nil
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un code_insee_localite' do
|
||||
expect(subject[:code_insee_localite]).to eq('75112')
|
||||
end
|
||||
end
|
||||
|
||||
context 'Détails adresse étranger' do
|
||||
let(:fixture) { 'spec/fixtures/files/api_entreprise/etablissements-uk.json' }
|
||||
|
||||
it 'L\'entreprise contient bien une localite' do
|
||||
expect(subject[:localite]).to eq('LONDRES')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un nom de pays' do
|
||||
expect(subject[:nom_pays]).to eq('ROYAUME-UNI')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'Attributs Etablissements pour etablissement non siege' do
|
||||
|
|
|
@ -443,7 +443,7 @@ describe Champ do
|
|||
end
|
||||
let(:champ) { Champs::SiretChamp.new(value: etablissement.siret, etablissement:) }
|
||||
|
||||
it { is_expected.to eq([etablissement.entreprise_siren, etablissement.entreprise_numero_tva_intracommunautaire, etablissement.entreprise_forme_juridique, etablissement.entreprise_forme_juridique_code, etablissement.entreprise_nom_commercial, etablissement.entreprise_raison_sociale, etablissement.entreprise_siret_siege_social, etablissement.entreprise_nom, etablissement.entreprise_prenom, etablissement.association_rna, etablissement.association_titre, etablissement.association_objet, etablissement.siret, etablissement.enseigne, etablissement.naf, etablissement.libelle_naf, etablissement.adresse, etablissement.code_postal, etablissement.localite, etablissement.code_insee_localite]) }
|
||||
it { is_expected.to eq([etablissement.entreprise_siren, etablissement.entreprise_numero_tva_intracommunautaire, etablissement.entreprise_forme_juridique, etablissement.entreprise_forme_juridique_code, etablissement.entreprise_nom_commercial, etablissement.entreprise_raison_sociale, etablissement.entreprise_siret_siege_social, etablissement.entreprise_nom, etablissement.entreprise_prenom, etablissement.association_rna, etablissement.association_titre, etablissement.association_objet, etablissement.siret, etablissement.enseigne, etablissement.naf, etablissement.libelle_naf, etablissement.adresse, etablissement.code_postal, etablissement.localite, etablissement.code_insee_localite, nil]) }
|
||||
end
|
||||
|
||||
context 'when there is no etablissement' do
|
||||
|
|
Loading…
Reference in a new issue