Skip to content

Commit

Permalink
Add ADSUser.date_location_gerance
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Feb 6, 2025
1 parent cb1f587 commit 0c35694
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
9 changes: 8 additions & 1 deletion mesads/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ def _should_delete_form(self, form):
# django.db.models.constraints.CheckConstraint.validate() will silently skip
# the evaluation of the constraints using this field.
# Does it suck? Yes. Did I spend 2 days to figure it out? Also yes.
fields=("status", "name", "siret", "license_number", "deleted_at"),
fields=(
"status",
"name",
"siret",
"license_number",
"date_location_gerance",
"deleted_at",
),
can_delete=True,
extra=0,
formset=AutoDeleteADSUserFormSet,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 5.0.6 on 2025-02-06 21:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("app", "0087_alter_ads_creation_date_alter_ads_last_update"),
]

operations = [
migrations.AddField(
model_name="adsuser",
name="date_location_gerance",
field=models.DateField(
blank=True,
null=True,
verbose_name="Date du contrat de location-gérance",
),
),
migrations.AddConstraint(
model_name="adsuser",
constraint=models.CheckConstraint(
check=models.Q(
("date_location_gerance__isnull", True),
models.Q(
("date_location_gerance__isnull", False),
("status", "locataire_gerant"),
),
_connector="OR",
),
name="ads_location_gerance_set_only_for_locataire_gerant",
violation_error_message="La date du contrat de location-gérance ne peut être renseignée que pour un locataire-gérant.",
),
),
]
12 changes: 12 additions & 0 deletions mesads/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,13 @@ class Meta:
name="siret_empty_for_salarie",
violation_error_message="Le SIRET du conducteur ne peut pas être renseigné pour un salarié.",
),
# date_location_gerance can only be set for locataire_gerant
models.CheckConstraint(
check=Q(date_location_gerance__isnull=True)
| Q(date_location_gerance__isnull=False, status="locataire_gerant"),
name="ads_location_gerance_set_only_for_locataire_gerant",
violation_error_message="La date du contrat de location-gérance ne peut être renseignée que pour un locataire-gérant.",
),
]

def __str__(self):
Expand Down Expand Up @@ -863,6 +870,11 @@ def save(self, *args, **kwargs):
null=False,
verbose_name="Numéro de la carte professionnelle",
)
date_location_gerance = models.DateField(
blank=True,
null=True,
verbose_name="Date du contrat de location-gérance",
)


class ADSUpdateFile(models.Model):
Expand Down
12 changes: 11 additions & 1 deletion mesads/templates/webpack/pages/ads_register/ads.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ <h1>
<input type="hidden" name="{{ ads_user_form.status.html_name }}" value="titulaire_exploitant" />
</template>

<!-- Date location gérance -->
<template x-if="status === 'locataire_gerant'">
{% include 'form_fields/date.html' with field=ads_user_form.date_location_gerance field_errors=ads_user_form.errors.date_location_gerance required=ads_user_form.fields.date_location_gerance.required readonly=ads_manager.is_locked %}
</template>

<!-- User name -->
<template x-if="ads_before_2014 && status !== 'titulaire_exploitant'">
{% include 'form_fields/string.html' with field=ads_user_form.name field_errors=ads_user_form.errors.name required=ads_user_form.fields.name.required readonly=ads_manager.is_locked %}
Expand Down Expand Up @@ -293,13 +298,18 @@ <h1>
<!-- User status -->
{% include 'form_fields/select.html' with x_model="status" field=ads_users_formset.empty_form.status field_errors=ads_users_formset.empty_form.errors.status required=ads_users_formset.empty_form.fields.status.required readonly=ads_manager.is_locked %}

<!-- Date location gérance -->
<template x-if="status === 'locataire_gerant'">
{% include 'form_fields/date.html' with field=ads_users_formset.empty_form.date_location_gerance field_errors=ads_users_formset.empty_form.errors.date_location_gerance required=ads_users_formset.empty_form.fields.date_location_gerance.required readonly=ads_manager.is_locked %}
</template>

<!-- User name -->
<template x-if="status !== 'titulaire_exploitant'">
{% include 'form_fields/string.html' with field=ads_users_formset.empty_form.name field_errors=ads_users_formset.empty_form.errors.name required=ads_users_formset.empty_form.fields.name.required readonly=ads_manager.is_locked %}
</template>

<!-- User SIRET -->
<template x-if="status !== 'titulaire_exploitant' && status !== 'legal_representative' && status !== 'salarie' ">
<template x-if="status !== 'titulaire_exploitant' && status !== 'legal_representative' && status !== 'salarie'">
{% include 'form_fields/string.html' with field=ads_users_formset.empty_form.siret field_errors=ads_users_formset.empty_form.errors.siret required=ads_users_formset.empty_form.fields.siret.required readonly=ads_manager.is_locked %}
</template>

Expand Down

0 comments on commit 0c35694

Please sign in to comment.