Skip to content

Commit

Permalink
déterminer la natureLogement quand elle est null selon la natureOpera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
kolok committed Feb 5, 2025
1 parent a6b1f0c commit c31b94d
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 42 deletions.
8 changes: 4 additions & 4 deletions conventions/forms/convention_form_financement.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def _pls_end_date_validation(self, annee_fin_conventionnement):
)
# No control on max date for foyer, residence and avenants
if (
self.convention.programme.is_foyer()
or self.convention.programme.is_residence()
self.convention.programme.is_foyer
or self.convention.programme.is_residence
or self.convention.is_avenant()
):
return
Expand Down Expand Up @@ -192,8 +192,8 @@ def _other_end_date_validation(self, annee_fin_conventionnement):
cdc_end_year = cdc_pret.cleaned_data["date_octroi"].year + 9
# don't add a year for FOYER because end of convention is the 31/12
if (
not self.convention.programme.is_foyer()
and not self.convention.programme.is_residence()
not self.convention.programme.is_foyer
and not self.convention.programme.is_residence
and end_conv
and end_conv.month > 6
):
Expand Down
2 changes: 1 addition & 1 deletion conventions/models/convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def lot(self) -> Lot:

@property
def attribution_type(self):
if not self.programme.is_foyer():
if not self.programme.is_foyer:
return None
if (
self.attribution_agees_autonomie
Expand Down
10 changes: 5 additions & 5 deletions conventions/services/convention_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class DocxGenerationError(Exception):
def get_convention_template_path(convention):
# pylint: disable=R0911
if convention.is_avenant():
if convention.programme.is_foyer() or convention.programme.is_residence():
if convention.programme.is_foyer or convention.programme.is_residence:
return f"{settings.BASE_DIR}/documents/FoyerResidence-Avenant-template.docx"
return f"{settings.BASE_DIR}/documents/Avenant-template.docx"
if convention.programme.is_foyer():
if convention.programme.is_foyer:
return f"{settings.BASE_DIR}/documents/Foyer-template.docx"
if convention.programme.is_residence():
if convention.programme.is_residence:
return f"{settings.BASE_DIR}/documents/Residence-template.docx"
if convention.programme.bailleur.is_hlm():
return f"{settings.BASE_DIR}/documents/HLM-template.docx"
Expand Down Expand Up @@ -599,7 +599,7 @@ def _list_to_dict(object_list):


def _get_residence_attributions(convention: Convention) -> str:
if not convention.programme.is_residence():
if not convention.programme.is_residence:
return ""

result = []
Expand All @@ -623,7 +623,7 @@ def _get_residence_attributions(convention: Convention) -> str:


def _get_foyer_attributions(convention: Convention) -> str:
if not convention.programme.is_foyer():
if not convention.programme.is_foyer:
return ""

return foyer_attributions_mapping.get(convention.attribution_type, "")
Expand Down
5 changes: 1 addition & 4 deletions conventions/services/financement.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ def _convention_financement_atomic_update(self):
self.redirect_recap = self.request.POST.get("redirect_to_recap", False)

def _save_convention_financement(self):
if (
self.convention.programme.is_foyer()
or self.convention.programme.is_residence()
):
if self.convention.programme.is_foyer or self.convention.programme.is_residence:
self.convention.date_fin_conventionnement = datetime.date(
self.form.cleaned_data["annee_fin_conventionnement"], 12, 31
)
Expand Down
2 changes: 1 addition & 1 deletion conventions/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def task_send_email_to_bailleur(

# Case 1 : need a zip with many files
if not convention.is_avenant() and (
convention.programme.is_foyer() or convention.programme.is_residence()
convention.programme.is_foyer or convention.programme.is_residence
):
local_pdf_path = local_path / f"convention_{convention.uuid}.pdf"
local_zip_path = local_path / f"convention_{convention.uuid}.zip"
Expand Down
4 changes: 2 additions & 2 deletions conventions/templatetags/custom_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ def display_type1and2(convention):
return (
convention.programme.bailleur.is_type1and2()
and not convention.is_avenant()
and not convention.programme.is_foyer()
and not convention.programme.is_residence()
and not convention.programme.is_foyer
and not convention.programme.is_residence
)


Expand Down
8 changes: 4 additions & 4 deletions conventions/tests/views/test_form_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_form_steps_basic(self):
def test_avenant_foyer_steps(self):
self.avenant.programme.nature_logement = NatureLogement.AUTRE
self.avenant.programme.save()
self.assertTrue(self.avenant.programme.is_foyer())
self.assertTrue(self.avenant.programme.is_foyer)

form_steps = ConventionFormSteps(convention=self.avenant, request=self.request)
self.assertEqual(
Expand All @@ -105,7 +105,7 @@ def test_avenant_foyer_steps(self):
def test_avenant_residence_steps(self):
self.avenant.programme.nature_logement = NatureLogement.HEBERGEMENT
self.avenant.programme.save()
self.assertTrue(self.avenant.programme.is_residence())
self.assertTrue(self.avenant.programme.is_residence)

form_steps = ConventionFormSteps(convention=self.avenant, request=self.request)
self.assertEqual(
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_avenant_comments_view_steps(self):
def test_programme_foyer_steps(self):
self.convention.programme.nature_logement = NatureLogement.AUTRE
self.convention.programme.save()
self.assertTrue(self.convention.programme.is_foyer())
self.assertTrue(self.convention.programme.is_foyer)

form_steps = ConventionFormSteps(
convention=self.convention, request=self.request
Expand All @@ -185,7 +185,7 @@ def test_programme_foyer_steps(self):
def test_programme_residence_steps(self):
self.convention.programme.nature_logement = NatureLogement.HEBERGEMENT
self.convention.programme.save()
self.assertTrue(self.convention.programme.is_residence())
self.assertTrue(self.convention.programme.is_residence)

form_steps = ConventionFormSteps(
convention=self.convention, request=self.request
Expand Down
2 changes: 1 addition & 1 deletion conventions/views/avenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def new_avenant(request: HttpRequest, convention_uuid: UUID) -> HttpResponse:
convention = result["convention"]
target_pathname = None
if result["avenant_type"].nom == "logements":
if convention.programme.is_foyer() or convention.programme.is_residence():
if convention.programme.is_foyer or convention.programme.is_residence:
target_pathname = "conventions:avenant_foyer_residence_logements"
else:
target_pathname = "conventions:avenant_logements"
Expand Down
8 changes: 4 additions & 4 deletions conventions/views/convention_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def __init__(
if convention.is_avenant():
varying_steps = (
[avenant_foyer_residence_logements_step, avenant_collectif_step]
if convention.programme.is_foyer()
or convention.programme.is_residence()
if convention.programme.is_foyer
or convention.programme.is_residence
else [
avenant_logements_step,
avenant_annexes_step,
Expand All @@ -263,9 +263,9 @@ def __init__(
avenant_commentaires_step,
]

elif convention.programme.is_foyer():
elif convention.programme.is_foyer:
self.steps = foyer_steps
elif convention.programme.is_residence():
elif convention.programme.is_residence:
self.steps = residence_steps
else:
self.steps = hlm_sem_type_steps
Expand Down
Binary file modified documents/FicheCAF-template.docx
Binary file not shown.
19 changes: 11 additions & 8 deletions programmes/models/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,17 @@ class ActiveNatureLogement(models.TextChoices):


class NatureLogement(models.TextChoices):
LOGEMENTSORDINAIRES = "LOGEMENTSORDINAIRES", "Logements ordinaires"
AUTRE = "AUTRE", "Autres logements foyers"
HEBERGEMENT = "HEBERGEMENT", "Hébergement"
RESISDENCESOCIALE = "RESISDENCESOCIALE", "Résidence sociale"
PENSIONSDEFAMILLE = "PENSIONSDEFAMILLE", "Pensions de famille (Maisons relais)"
RESIDENCEDACCUEIL = "RESIDENCEDACCUEIL", "Résidence d'accueil"
RESIDENCEUNIVERSITAIRE = "RESIDENCEUNIVERSITAIRE", "Résidence universitaire"
RHVS = "RHVS", "RHVS"
LOGEMENTSORDINAIRES = "LOGEMENTSORDINAIRES", "Logements ordinaires" # LOO
AUTRE = "AUTRE", "Autres logements foyers" # ALF
HEBERGEMENT = "HEBERGEMENT", "Hébergement" # HEB
RESISDENCESOCIALE = "RESISDENCESOCIALE", "Résidence sociale" # RES
PENSIONSDEFAMILLE = (
"PENSIONSDEFAMILLE",
"Pensions de famille (Maisons relais)",
) # PEF
RESIDENCEDACCUEIL = "RESIDENCEDACCUEIL", "Résidence d'accueil" # REA
RESIDENCEUNIVERSITAIRE = "RESIDENCEUNIVERSITAIRE", "Résidence universitaire" # REU
RHVS = "RHVS", "RHVS" # RHVS

@classmethod
def eligible_for_update(cls):
Expand Down
4 changes: 3 additions & 1 deletion programmes/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def clean(self):
if not self.is_outre_mer:
return

if not (self.is_residence() or self.is_foyer()):
if not (self.is_residence or self.is_foyer):
raise OutreMerNatureLogementError(
"Un programme situé en outre-mer ne peut être que de nature foyer ou résidence."
)
Expand Down Expand Up @@ -316,9 +316,11 @@ def edd_stationnements_text(self):
def edd_stationnements_files(self):
return get_key_from_json_field(self.edd_stationnements, "files", default={})

@property
def is_foyer(self):
return self.nature_logement in [NatureLogement.AUTRE]

@property
def is_residence(self):
return self.nature_logement in [
NatureLogement.HEBERGEMENT,
Expand Down
4 changes: 2 additions & 2 deletions programmes/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ def test_is_residence(self):
NatureLogement.RESISDENCESOCIALE,
]:
programme.nature_logement = nature_logement
self.assertTrue(programme.is_residence())
self.assertTrue(programme.is_residence)
for nature_logement in [
NatureLogement.LOGEMENTSORDINAIRES,
NatureLogement.AUTRE,
NatureLogement.RESIDENCEUNIVERSITAIRE,
NatureLogement.RHVS,
]:
programme.nature_logement = nature_logement
self.assertFalse(programme.is_residence())
self.assertFalse(programme.is_residence)

def test_code_insee(self):
bailleur = Bailleur.objects.all().order_by("uuid").first()
Expand Down
58 changes: 53 additions & 5 deletions siap/siap_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@
ADDRESS_PC_CITY = "adresseLigne6"
ADDRESS_LINE_RAW = "adresseLigne4"
ADDRESS_CLEANED = "adresseLigne"
MAPPING_NATURE_OPERATION_TO_NATURE_LOGEMENT = {
# "PSLA": "PSLA",
# "DEMOLITION": "DEMOLITION",
"CADA": "HEB",
"CHRS": "HEB",
"CPH": "HEB",
"DEROG3": "LOO",
"DEROG3CCH": "LOO",
"DEROG3DEROG5": "LOO",
"EHPAD": "ALF",
"FJT": "RES",
"FOYERAM": "ALF",
"FOYERHEBER": "ALF",
"FOYEROCC": "ALF",
"FOYERPAPH": "ALF",
"FOYERVIE": "ALF",
"LITAM": "HEB",
"LITHSS": "HEB",
"LLSFAMDEROG3": "LOO",
"LLSFAMMIXTE": "LOO",
"LLSFAMORDIN": "LOO",
"MARPA": "ALF",
"PDF": "PEF",
"PUV": "ALF",
"RAC": "REA",
"RAU": "ALF",
"RENO_LF": "ALF", # "PEF","REA","RES",
"RENO_LLS": "LOO", # "REU",
"RESSOCJA": "RES",
"RHVSINTGEN": "RHVS",
"RHVSMOB": "RHVS",
"RSG": "RES",
"RU": "REU",
}


def get_or_create_programme_from_siap_operation(operation: dict) -> Programme:
Expand Down Expand Up @@ -216,7 +250,6 @@ def _get_address_from_locdata(loc_data: dict) -> tuple[str]:
def get_or_create_programme(
programme_from_siap: dict, bailleur: Bailleur, administration: Administration
) -> Programme:
nature_logement = NatureLogement.LOGEMENTSORDINAIRES
if (
"sansTravaux" in programme_from_siap["donneesOperation"]
and programme_from_siap["donneesOperation"]["sansTravaux"]
Expand All @@ -226,9 +259,8 @@ def get_or_create_programme(
type_operation = _type_operation(
programme_from_siap["donneesOperation"]["sousNatureOperation"]
)
nature_logement = _nature_logement(
programme_from_siap["donneesOperation"]["natureLogement"]
)
nature_logement = _get_nature_logement(programme_from_siap["donneesOperation"])

(adresse, code_postal, ville) = _get_address_from_locdata(
programme_from_siap["donneesLocalisation"]
)
Expand Down Expand Up @@ -398,7 +430,23 @@ def _type_operation(type_operation_from_siap: str) -> TypeOperation:
return TypeOperation.SANSOBJET


def _nature_logement(nature_logement_from_siap: str) -> TypeOperation:
def _get_nature_logement(donnees_operation: dict) -> NatureLogement:
nature_logement = ""
if "natureLogement" in donnees_operation and donnees_operation["natureLogement"]:
nature_logement = donnees_operation["natureLogement"]
elif (
"natureOperation" in donnees_operation
and donnees_operation["natureOperation"]
in MAPPING_NATURE_OPERATION_TO_NATURE_LOGEMENT.keys()
):
nature_logement = MAPPING_NATURE_OPERATION_TO_NATURE_LOGEMENT[
donnees_operation["natureOperation"]
]

return _nature_logement(nature_logement)


def _nature_logement(nature_logement_from_siap: str) -> NatureLogement:
if nature_logement_from_siap in ["ALF", NatureLogement.AUTRE]:
nature_logement = NatureLogement.AUTRE
elif nature_logement_from_siap in ["HEB", NatureLogement.HEBERGEMENT]:
Expand Down

0 comments on commit c31b94d

Please sign in to comment.