Skip to content

Commit

Permalink
feat(admin): dynamic SIRET columns list
Browse files Browse the repository at this point in the history
  • Loading branch information
colinux committed Dec 6, 2024
1 parent c031201 commit 3b67345
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 49 deletions.
36 changes: 16 additions & 20 deletions app/controllers/administrateurs/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,26 +424,22 @@ def administrateurs

def api_champ_columns
_, @type_de_champ = @procedure.draft_revision.coordinate_and_tdc(params[:stable_id])
@columns = [
"Raison sociale",
"Adresse du siège social",
"Code NAF",
"Libellé NAF",
"Date de création",
"Numéro TVA intracommunautaire",
"Attestation sociale",
"Attestation fiscale",
"Raison sociale",
"Adresse du siège social",
"Code NAF",
"Libellé NAF",
"Date de création",
"Numéro TVA intracommunautaire",
"Attestation sociale",
"Attestation fiscale"
].map do |label|
Column.new(procedure_id: @procedure.id, table: :etablissement, column: nil, label:)
end.sort_by(&:label)
regex_prefix = /^#{Regexp.escape(@type_de_champ.libelle)}([^\p{L}]+SIRET)?[^\p{L}]+/

Check warning on line 427 in app/controllers/administrateurs/procedures_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/procedures_controller.rb#L426-L427

Added lines #L426 - L427 were not covered by tests

@column_labels = @type_de_champ

Check warning on line 429 in app/controllers/administrateurs/procedures_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/procedures_controller.rb#L429

Added line #L429 was not covered by tests
.columns(procedure: @procedure)
.filter_map do |column|
# Remove tdc libelle prefix added in columns:
# Numéro SIRET - Entreprise SIREN => Entreprise SIREN
column.label.sub(regex_prefix, '')

Check warning on line 434 in app/controllers/administrateurs/procedures_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/procedures_controller.rb#L434

Added line #L434 was not covered by tests
end

if @type_de_champ.type_champ == "siret"
@column_labels.concat Etablissement::EXPORTABLE_COLUMNS.dup.map { I18n.t(_1, scope: [:activerecord, :attributes, :procedure_presentation, :fields, :etablissement]) }

# Hardcode non columns data
@column_labels << "Bilans BDF"

Check warning on line 441 in app/controllers/administrateurs/procedures_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/procedures_controller.rb#L441

Added line #L441 was not covered by tests
end
end

private
Expand Down
26 changes: 1 addition & 25 deletions app/models/concerns/columns_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,7 @@ def moral_columns

others = %w[code_postal].map { |column| dossier_col(table: 'etablissement', column:) }

for_export = %w[
siege_social
code_naf
adresse
numero_voie
type_voie
nom_voie
complement_adresse
localite
code_insee_localite
entreprise_capital_social
entreprise_numero_tva_intracommunautaire
entreprise_forme_juridique_code
entreprise_code_effectif_entreprise
entreprise_etat_administratif
entreprise_siret_siege_social
entreprise_nom
entreprise_prenom
association_rna
association_titre
association_objet
association_date_creation
association_date_declaration
association_date_publication
].map { |column| dossier_col(table: 'etablissement', column:, displayable: false, filterable: false) }
for_export = Etablissement::EXPORTABLE_COLUMNS.map { |column| dossier_col(table: 'etablissement', column:) }

[siret_column, etablissements, others, for_export].flatten
end
Expand Down
26 changes: 26 additions & 0 deletions app/models/etablissement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ class Etablissement < ApplicationRecord
"libelle_naf" => { type: :text }
}.freeze

EXPORTABLE_COLUMNS = %w[
siege_social
code_naf
adresse
numero_voie
type_voie
nom_voie
complement_adresse
localite
code_insee_localite
entreprise_capital_social
entreprise_numero_tva_intracommunautaire
entreprise_forme_juridique_code
entreprise_code_effectif_entreprise
entreprise_etat_administratif
entreprise_siret_siege_social
entreprise_nom
entreprise_prenom
association_rna
association_titre
association_objet
association_date_creation
association_date_declaration
association_date_publication
].freeze

def entreprise_raison_sociale
read_attribute(:entreprise_raison_sociale).presence || raison_sociale_for_ei
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
= t('.hint_html')

%ul.two-column-list.fr-mb-3w
- @columns.each do |column|
%li= column.label
- @column_labels.each do |label|
%li= label.upcase_first

- if @type_de_champ.type_champ == "siret"
%p.fr-hint-text
Expand Down
5 changes: 3 additions & 2 deletions spec/system/administrateurs/types_de_champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
end

context "SIRET field modal" do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret, libelle: "SIRET de test" }]) }

scenario "loads modal content only when clicked" do
visit champs_admin_procedure_path(procedure)
Expand All @@ -426,7 +426,8 @@

within "#api-champ-columns-modal" do
expect(page).to have_content("Informations complémentaires au champ Numéro Siret")
expect(page).to have_content("Adresse du siège social")
expect(page).to have_content("Entreprise raison sociale")
expect(page).not_to have_content("SIRET de test – Commune") # no champ libelle

click_button "Fermer"
end
Expand Down

0 comments on commit 3b67345

Please sign in to comment.