Skip to content

Commit

Permalink
Update avenants logements
Browse files Browse the repository at this point in the history
  • Loading branch information
syldb committed Jan 20, 2025
1 parent a23d787 commit eebe33c
Show file tree
Hide file tree
Showing 21 changed files with 1,529 additions and 295 deletions.
4 changes: 2 additions & 2 deletions apilos_settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Commune(models.Model):
commune = models.CharField(max_length=255, blank=True)
# Needed to import xlsx files
import_mapping = {
"Code postal": code_postal,
"Commune": commune,
"Code postal": "code_postal",
"Commune": "commune",
}
sheet_name: str = "Communes"

Expand Down
118 changes: 108 additions & 10 deletions conventions/forms/convention_form_logements.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ class LotLgtsOptionForm(forms.Form):
"required": "Le nombre de logements est obligatoire",
},
)
formset_sans_loyer_disabled = forms.BooleanField(
required=False,
)
formset_disabled = forms.BooleanField(
required=False,
)
formset_corrigee_disabled = forms.BooleanField(
required=False,
)
formset_corrigee_sans_loyer_disabled = forms.BooleanField(
required=False,
)


class LotFoyerResidenceLgtsDetailsForm(forms.Form):
Expand Down Expand Up @@ -129,12 +141,7 @@ def clean_surface_habitable_totale(self):
return surface_habitable_totale


class LogementForm(forms.Form):
"""
Formulaire Logement formant la liste des logements d'une convention de type HLM,
SEM, type I & 2 : une ligne du tableau des logements
"""

class BaseLogementForm(forms.Form):
uuid = forms.UUIDField(
required=False,
label="Logement",
Expand Down Expand Up @@ -166,6 +173,88 @@ class LogementForm(forms.Form):
"max_digits": "La surface habitable doit-être inférieur à 10000 m²",
},
)
import_order = forms.IntegerField(
label="",
required=False,
)


class LogementCorrigeeSansLoyerForm(BaseLogementForm):
surface_corrigee = forms.DecimalField(
label="",
max_digits=6,
decimal_places=2,
error_messages={
"required": "La surface corrigée est obligatoire",
"max_digits": "La surface corrigée doit-être inférieur à 10000 m²",
},
)


class LogementCorrigeeForm(LogementCorrigeeSansLoyerForm):
loyer_par_metre_carre = forms.DecimalField(
label="",
max_digits=6,
decimal_places=2,
error_messages={
"required": "Le loyer par m² est obligatoire",
"max_digits": "La loyer par m² doit-être inférieur à 10000 €",
},
)
coeficient = forms.DecimalField(
required=True,
label="",
max_digits=6,
decimal_places=4,
error_messages={
"required": "Le coefficient est obligatoire",
"max_digits": "La coefficient doit-être inférieur à 1000",
},
)
loyer = forms.DecimalField(
required=True,
label="",
max_digits=6,
decimal_places=2,
error_messages={
"required": "Le loyer est obligatoire",
"max_digits": "La loyer doit-être inférieur à 10000 €",
},
)

def clean_loyer(self):
"""
Vérifcations:
- le loyer doit-être le produit de la surface utile, du loyer par mètre carré et
du coefficient (tolérance de 1 €)
"""
surface_corrigee = self.cleaned_data.get("surface_corrigee", 0)
loyer_par_metre_carre = self.cleaned_data.get("loyer_par_metre_carre", 0)
coeficient = self.cleaned_data.get("coeficient", 0)
loyer = self.cleaned_data.get("loyer", 0)

if (
abs(
round_half_up(loyer, 2)
- round_half_up(surface_corrigee * loyer_par_metre_carre * coeficient, 2)
)
> 1
):
raise ValidationError(
"Le loyer doit-être le produit de la surface corrigée,"
+ " du loyer par mètre carré et du coefficient. valeur attendue :"
+ f" {round_half_up(surface_corrigee*loyer_par_metre_carre*coeficient,2)} €"
+ " (tolérance de 1 €)"
)

return loyer


class LogementSansLoyerForm(BaseLogementForm):
"""
Formulaire Logement formant la liste des logements d'une convention de type HLM,
SEM, type I & 2 : une ligne du tableau des logements par surface réelle sans loyers
"""
surface_annexes = forms.DecimalField(
label="",
max_digits=6,
Expand Down Expand Up @@ -193,6 +282,14 @@ class LogementForm(forms.Form):
"max_digits": "La surface utile doit-être inférieur à 10000 m²",
},
)


class LogementForm(LogementSansLoyerForm):
"""
Formulaire Logement formant la liste des logements d'une convention de type HLM,
SEM, type I & 2 : une ligne du tableau des logements
"""

loyer_par_metre_carre = forms.DecimalField(
label="",
max_digits=6,
Expand All @@ -203,6 +300,7 @@ class LogementForm(forms.Form):
},
)
coeficient = forms.DecimalField(
required=True,
label="",
max_digits=6,
decimal_places=4,
Expand All @@ -212,6 +310,7 @@ class LogementForm(forms.Form):
},
)
loyer = forms.DecimalField(
required=True,
label="",
max_digits=6,
decimal_places=2,
Expand All @@ -220,10 +319,6 @@ class LogementForm(forms.Form):
"max_digits": "La loyer doit-être inférieur à 10000 €",
},
)
import_order = forms.IntegerField(
label="",
required=False,
)

def clean_loyer(self):
"""
Expand Down Expand Up @@ -413,6 +508,9 @@ def manage_coefficient_propre(self):


LogementFormSet = formset_factory(LogementForm, formset=BaseLogementFormSet, extra=0)
LogementSansLoyerFormSet = formset_factory(LogementSansLoyerForm, formset=BaseLogementFormSet, extra=0)
LogementCorrigeeFormSet = formset_factory(LogementCorrigeeForm, formset=BaseLogementFormSet, extra=0)
LogementCorrigeeSansLoyerFormSet = formset_factory(LogementCorrigeeSansLoyerForm, formset=BaseLogementFormSet, extra=0)


class FoyerResidenceLogementForm(forms.Form):
Expand Down
2 changes: 1 addition & 1 deletion conventions/forms/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class UploadForm(forms.Form):
+ "de cliquer sur le bouton 'Déposer'"
),
}
)
)
12 changes: 6 additions & 6 deletions conventions/models/pret.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class Pret(models.Model):

# Needed to import xlsx files
import_mapping = {
"Numéro\n(caractères alphanuméric)": numero,
"Date d'octroi\n(format dd/mm/yyyy)": date_octroi,
"Durée\n(en années)": duree,
"Montant\n(en €)": montant,
"Prêteur\n(choisir dans la liste déroulante)": preteur,
"Préciser l'identité du préteur si vous avez sélectionné 'Autre'": autre,
"Numéro\n(caractères alphanuméric)": "numero",
"Date d'octroi\n(format dd/mm/yyyy)": "date_octroi",
"Durée\n(en années)": "duree",
"Montant\n(en €)": "montant",
"Prêteur\n(choisir dans la liste déroulante)": "preteur",
"Préciser l'identité du préteur si vous avez sélectionné 'Autre'": "autre",
}
sheet_name = "Financements"

Expand Down
4 changes: 4 additions & 0 deletions conventions/services/convention_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ class PDFConversionError(Exception):
pass


class DocxGenerationError(Exception):
pass


def run_pdf_convert_cmd(
src_docx_path: Path, dst_pdf_path: Path
) -> subprocess.CompletedProcess:
Expand Down
3 changes: 3 additions & 0 deletions conventions/services/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class ConventionService(ABC):
editable_after_upload: bool = False
form: Form | None = None
formset = None
formset_sans_loyer = None
formset_corrigee = None
formset_corrigee_sans_loyer = None
upform: Form | None = None
extra_forms: dict[str, Form | None] | None = None

Expand Down
Loading

0 comments on commit eebe33c

Please sign in to comment.