Skip to content

Commit

Permalink
[FIX]Include recent changes
Browse files Browse the repository at this point in the history
Merge pull request #417 from annuaire-entreprises-data-gouv-fr/fix-regressions
  • Loading branch information
HAEKADI authored Sep 2, 2024
2 parents d4a7c10 + cf8ae28 commit d531675
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
12 changes: 12 additions & 0 deletions app/doc/open-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,12 @@ paths:
distribution spéciale + (code postal + libelle
commune | cedex + libelle cedex) + libelle commune
étranger + libelle pays étranger*
ancien_siege:
type: boolean
example: false
description: >-
L'établissement était le siège de
l'unité légale (source : base SIRENE).
caractere_employeur:
type: string
example: "O"
Expand Down Expand Up @@ -1936,6 +1942,12 @@ paths:
distribution spéciale + (code postal + libelle
commune | cedex + libelle cedex) + libelle commune
étranger + libelle pays étranger*
ancien_siege:
type: boolean
example: false
description: >-
L'établissement était le siège de
l'unité légale (source : base SIRENE).
caractere_employeur:
type: string
example: "O"
Expand Down
1 change: 1 addition & 0 deletions app/models/unite_legale.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class Etablissement(BaseModel):
activite_principale: str | None = None
activite_principale_registre_metier: str | None = None
ancien_siege: bool | None = None
annee_tranche_effectif_salarie: str | None = None
adresse: str | None = None
caractere_employeur: str | None = None
Expand Down
3 changes: 2 additions & 1 deletion app/service/format_search_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from app.service.formatters.immatriculation import format_immatriculation
from app.service.formatters.nature_juridique import format_nature_juridique
from app.service.formatters.nom_complet import format_nom_complet
from app.service.formatters.nom_complet import format_nom_complet, get_nom_commercial
from app.service.formatters.non_diffusible import (
hide_non_diffusible_fields,
)
Expand All @@ -38,6 +38,7 @@ def get_field(field, default=None):
"nom_complet": format_nom_complet(
get_field("nom_complet"),
get_field("sigle"),
get_nom_commercial(get_field("siege")),
get_field("denomination_usuelle_1_unite_legale"),
get_field("denomination_usuelle_2_unite_legale"),
get_field("denomination_usuelle_3_unite_legale"),
Expand Down
2 changes: 2 additions & 0 deletions app/service/formatters/etablissements.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def get_field(field, default=None):
"activite_principale_registre_metier"
),
"annee_tranche_effectif_salarie": get_field("annee_tranche_effectif_salarie"),
"ancien_siege": get_field("ancien_siege"),
"adresse": get_field("adresse"),
"caractere_employeur": get_field("caractere_employeur"),
"cedex": get_field("cedex"),
Expand Down Expand Up @@ -113,4 +114,5 @@ def format_siege(siege=None):
if not siege:
return {}
siege_formatted = format_etablissement(siege).dict()
del siege_formatted["ancien_siege"]
return Etablissement(**siege_formatted)
46 changes: 31 additions & 15 deletions app/service/formatters/nom_complet.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
def get_nom_commercial(siege):
return siege.get("nom_commercial", None) if siege else None


def format_nom_complet(
nom_complet,
sigle=None,
nom_commercial_siege=None,
denomination_usuelle_1=None,
denomination_usuelle_2=None,
denomination_usuelle_3=None,
):
"""Add `denomination usuelle` fields and `sigle` to `nom_complet`."""
all_denomination_usuelle = ""
for item in [
denomination_usuelle_1,
denomination_usuelle_2,
denomination_usuelle_3,
]:
if item:
all_denomination_usuelle += f"{item} "
if all_denomination_usuelle:
nom_complet = f"{nom_complet} ({all_denomination_usuelle.strip()})"
if not nom_complet:
return None

# Handle denomination usuelle
if nom_commercial_siege:
denomination = nom_commercial_siege
else:
denomination = " ".join(
filter(
None,
[
denomination_usuelle_1,
denomination_usuelle_2,
denomination_usuelle_3,
],
)
)

# Add denomination to nom_complet if it exists
if denomination:
nom_complet += f" ({denomination.strip()})"

# Add sigle if it exists
if sigle:
nom_complet = f"{nom_complet} ({sigle})"
if nom_complet:
return nom_complet.upper()
# if nom_complet is null
return None
nom_complet += f" ({sigle})"

return nom_complet.upper()

0 comments on commit d531675

Please sign in to comment.