Skip to content

Commit

Permalink
feat(champ.rnf/rna/siret): render normalized address the same way
Browse files Browse the repository at this point in the history
  • Loading branch information
mfo committed Aug 21, 2024
1 parent 8cdd7ef commit 75dea57
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 46 deletions.
6 changes: 0 additions & 6 deletions app/models/champs/rna_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ def search_terms
etablissement.present? ? etablissement.search_terms : [value]
end

def full_address
address = data&.dig("adresse")
return if address.blank?
"#{address["numero_voie"]} #{address["type_voie"]} #{address["libelle_voie"]} #{address["code_postal"]} #{address["commune"]}"
end

def rna_address
address = data&.dig("adresse")
return if address.blank?
Expand Down
4 changes: 4 additions & 0 deletions app/services/api_geo_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def departement_name(code)
departements.find { _1[:code] == code }&.dig(:name)
end

def departement_name_by_postal_code(postal_code)
APIGeoService.departement_name(postal_code[0..2]) || APIGeoService.departement_name(postal_code[0..1])
end

def departement_code(name)
return if name.nil?
departements.find { _1[:name] == name }&.dig(:code)
Expand Down
11 changes: 1 addition & 10 deletions app/views/shared/champs/rna/_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,4 @@
- c.with_value do
%p= l(champ.data[scope].to_date)

- if champ.data['address'].present?
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rna_champ.data.address")) do |c|
- c.with_value do
%p= champ.full_address

- ['code_insee', 'code_postal'].each do |scope|
- if champ.data['address'][scope].present?
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rna_champ.data.#{scope}")) do |c|
- c.with_value do
%p= champ.data['address'][scope]
= render partial: "shared/dossiers/normalized_address", locals: { address: Address.new(champ) }
10 changes: 1 addition & 9 deletions app/views/shared/champs/rnf/_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,4 @@
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rnf_champ.data.#{scope}")) do |c|
- c.with_value do
%p= l(champ.data[scope].to_date)

- if champ.data['address'].present?
- ['label', 'cityCode', 'postalCode'].each do |scope|
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rnf_champ.data.#{scope}")) do |c|
- c.with_value do
%p= champ.data['address'][scope]
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.rnf_champ.data.department")) do |c|
- c.with_value do
%p= "#{champ.data['address']['departmentCode']}#{champ.data['address']['departmentName']}"
= render partial: "shared/dossiers/normalized_address", locals: { address: Address.new(champ) }
2 changes: 1 addition & 1 deletion app/views/shared/champs/siret/_show.html.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- if champ.etablissement.present?
= render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: champ.etablissement, profile: profile }
= render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: champ.etablissement, profile: profile, champ: }
7 changes: 1 addition & 6 deletions app/views/shared/dossiers/_identite_entreprise.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@
- c.with_value do
%p= etablissement.entreprise.numero_tva_intracommunautaire

= render Dossiers::RowShowComponent.new(label: "Adresse") do |c|
- c.with_value do
%p
- etablissement.adresse.split("\n").compact_blank.each do |line|
= line
%br
= render partial: "shared/dossiers/normalized_address", locals: { address: Address.new(etablissement)}

= render Dossiers::RowShowComponent.new(label: "Capital social") do |c|
- c.with_value do
Expand Down
23 changes: 23 additions & 0 deletions app/views/shared/dossiers/_normalized_address.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.full_address")) do |c|
- c.with_value do
%p
= address.street_address
%br
= [address.city_name, address.postal_code].join(" ")


- ['city_code', 'postal_code'].each do |scope|
- if address.public_send(scope).present?
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.#{scope}")) do |c|
- c.with_value do
%p= address.public_send(scope)

- if address.departement_name.present?
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.department")) do |c|
- c.with_value do
%p= "#{address.departement_name}#{address.departement_code}"

- if address.region_name.present?
= render Dossiers::RowShowComponent.new(label: t("activemodel.attributes.normalized_address.region")) do |c|
- c.with_value do
%p= "#{address.region_name}#{address.region_code}"
9 changes: 9 additions & 0 deletions config/locales/models/champs/normalized_address/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
en:
activemodel:
attributes:
normalized_address:
full_address: Address
city_code: INSEE code
postal_code: Postal code
department: Department
region: Region & region code
9 changes: 9 additions & 0 deletions config/locales/models/champs/normalized_address/fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fr:
activemodel:
attributes:
normalized_address:
full_address: Adresse
city_code: Code INSEE
postal_code: Code postal
department: Département
region: Region & region code
3 changes: 0 additions & 3 deletions config/locales/models/champs/rna_champ/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ en:
association_date_creation: Creation date
association_date_declaration: Declaration date
association_date_publication: Publication date
address: Address
code_insee: INSEE code
code_postal: Postal code
paste: Copy the RNA to the clipboard
paste_success: The RNA has been copied to the clipboard
activerecord:
Expand Down
3 changes: 0 additions & 3 deletions config/locales/models/champs/rna_champ/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ fr:
association_date_creation: Date de création
association_date_declaration: Date de déclaration
association_date_publication: Date de publication
address: Adresse
code_insee: Code INSEE
code_postal: Code postal
paste: Copier le RNA dans le presse-papier
paste_success: Le RNA a été copié dans le presse-papier
activerecord:
Expand Down
4 changes: 0 additions & 4 deletions config/locales/models/champs/rnf_champ/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ en:
dissolvedAt: Dissolved at
address: Address
status: Status
cityCode: City code
postalCode: Postal code
department: Department
label: Address
paste: Copy the RNF to the clipboard
paste_success: The RNF has been copied to the clipboard
activerecord:
Expand Down
4 changes: 0 additions & 4 deletions config/locales/models/champs/rnf_champ/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ fr:
dissolvedAt: Dissoute le
address: Adresse
status: Statut
cityCode: Code INSEE
postalCode: Code postal
department: Département
label: Adresse
paste: Copier le RNF dans le presse-papier
paste_success: Le RNF a été copié dans le presse-papier
activerecord:
Expand Down

0 comments on commit 75dea57

Please sign in to comment.