Skip to content

Commit

Permalink
Remove transaction identifier, attribution type and attribution reason
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Aug 1, 2024
1 parent dda5306 commit 97b8b80
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 121 deletions.
1 change: 0 additions & 1 deletion mesads/app/admin/ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ def has_delete_permission(self, request, obj=None):
ADSPeriodListFilter,
"adsuser__status",
ADSUsersCount,
"attribution_type",
"accepted_cpam",
]

Expand Down
4 changes: 1 addition & 3 deletions mesads/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ class Meta:
"ads_in_use",
"ads_renew_date",
"attribution_date",
"attribution_type",
"transaction_identifier",
"attribution_reason",
"accepted_cpam",
"immatriculation_plate",
"vehicle_compatible_pmr",
Expand All @@ -105,6 +102,7 @@ class Meta:
"owner_phone",
"owner_mobile",
"owner_email",
"notes",
)

def __init__(self, epci=None, *args, **kwargs):
Expand Down
5 changes: 0 additions & 5 deletions mesads/app/management/commands/import_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,6 @@ def load_ads(self, cols, override=False):
self.excel.idx("email du titulaire"),
)

if not ads.attribution_type:
ads.attribution_type = ""
if not ads.attribution_reason:
ads.attribution_reason = ""

ads_users = self.load_ads_users(cols, ads)
return ads, ads_users

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,10 @@ def import_ads(self, ads_manager, all_paris_ads, row):
ads.vehicle_compatible_pmr = True
else:
ads.vehicle_compatible_pmr = None
# New ADS always have empty attribution type, reason and identifier.
if not ads.ads_creation_date or ads.ads_creation_date >= date(2014, 10, 1):
ads.attribution_type = ""
ads.attribution_reason = ""
ads.transaction_identifier = ""
ads.notes = ""
else:
if row["type_ads"] == "Payante":
ads.attribution_type = "paid"
elif row["type_ads"] in ("Gratuite cessible", "Gratuite non cessible"):
ads.attribution_type = "free"
else:
ads.attribution_type = ""
ads.attribution_reason = ""
if row["type_ads"] == "Relais":
ads.attribution_reason = "Relais"
ads.notes = f'Type d\'ADS : {row["type_ads"]}'

ads.immatriculation_plate = row["immatriculation"]

Expand Down
56 changes: 56 additions & 0 deletions mesads/app/migrations/0085_ads_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 5.0.6 on 2024-08-01 08:39

from django.db import migrations, models
from django.db.models import Q


def move_data_to_notes(apps, schema_editor):
ADS = apps.get_model("app", "ADS")

for ads in ADS.objects.filter(
~Q(attribution_type="")
| ~Q(transaction_identifier="")
| ~Q(attribution_reason="")
):
notes = []
if ads.attribution_type != "":
notes.append(
{
"paid": "* L'ADS a été cédée au titulaire actuel à titre onéreux",
"free": "* L'ADS a été délivrée au titulaire actuel par l'autorité compétente",
"other": "",
}[ads.attribution_type]
)
if ads.transaction_identifier:
notes.append(
f"* Numéro d'identification lié au registre des transactions : {ads.transaction_identifier}"
)
if ads.attribution_reason:
notes.append(
f"* Raison de l'attribution de l'ADS au titulaire actuel : {ads.attribution_reason}"
)
ads.notes = "\n".join(notes)
ads.save()


def do_nothing(apps, schema_editor):
pass


class Migration(migrations.Migration):
dependencies = [
("app", "0084_alter_adsmanager_administrator"),
]

operations = [
migrations.AddField(
model_name="ads",
name="notes",
field=models.TextField(
blank=True,
help_text="Champ libre pour les informations complémentaires utiles (numéro d'enregistrement dans le registre des transactions, informations importantes concernant la délivrance ou la cession de l'ADS, etc…)",
verbose_name="Notes sur l'ADS",
),
),
migrations.RunPython(move_data_to_notes, do_nothing),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 5.0.6 on 2024-08-01 17:29

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("app", "0085_ads_notes"),
]

operations = [
migrations.RemoveConstraint(
model_name="ads",
name="attribution_type_empty_for_new_ads",
),
migrations.RemoveConstraint(
model_name="ads",
name="transaction_identifier_empty_for_non_paid_ads",
),
migrations.RemoveConstraint(
model_name="ads",
name="attribution_reason_empty_for_new_ads",
),
migrations.RemoveField(
model_name="ads",
name="attribution_reason",
),
migrations.RemoveField(
model_name="ads",
name="attribution_type",
),
migrations.RemoveField(
model_name="ads",
name="transaction_identifier",
),
]
88 changes: 9 additions & 79 deletions mesads/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,55 +412,6 @@ class Meta:
name="attribution_date_null_for_new_ads",
violation_error_message="La date d'attribution ne peut être renseignée que pour les ADS créées avant le 1er octobre 2014.",
),
# Check attribution_type:
# - For new ADS, attribution_type should always be empty
# - For old ADS, attribution_type can be set or not
# - For ADS with an unknown creation date, attribution_type should be empty
models.CheckConstraint(
check=(
Q(
ads_creation_date__isnull=False,
ads_creation_date__gte=date(2014, 10, 1),
attribution_type="",
)
| Q(
ads_creation_date__isnull=False,
ads_creation_date__lt=date(2014, 10, 1),
)
| Q(ads_creation_date__isnull=True, attribution_type="")
),
name="attribution_type_empty_for_new_ads",
violation_error_message="Le champ 'Type d'attribution de l'ADS' ne peut être renseigné que pour les ADS créées avant le 1er octobre 2014.",
),
# Check transaction_identifier: the field can only be set if attribution_type is "paid"
models.CheckConstraint(
check=(
Q(attribution_type="paid")
| Q(~Q(attribution_type="paid"), transaction_identifier="")
),
name="transaction_identifier_empty_for_non_paid_ads",
violation_error_message="Le champ 'Numéro d'identification lié au registre des transactions' ne peut être renseigné que pour les ADS dont le type d'attribution est 'Cession à titre onéreux'.",
),
# Check attribution_reason:
# - For new ADS, attribution_reason should always be empty
# - For old ADS, attribution_reason can be set or not
# - For ADS with an unknown creation date, attribution_reason should be empty
models.CheckConstraint(
check=(
Q(
ads_creation_date__isnull=False,
ads_creation_date__gte=date(2014, 10, 1),
attribution_reason="",
)
| Q(
ads_creation_date__isnull=False,
ads_creation_date__lt=date(2014, 10, 1),
)
| Q(ads_creation_date__isnull=True, attribution_reason="")
),
name="attribution_reason_empty_for_new_ads",
violation_error_message="Le champ 'Raison d'attribution' ne peut être renseigné que pour les ADS créées avant le 1er octobre 2014.",
),
# Check renewal date nullable:
# - For new ADS, renew date can be set or not
# - For old ADS, renew date must always be empty
Expand Down Expand Up @@ -590,36 +541,6 @@ def unique_error_message(self, model_class, unique_check):
help_text="Laissez ce champ vide si le titulaire n'a pas changé depuis la création de l'ADS.",
)

ATTRIBUTION_TYPES = [
("free", "Délivrée par l'autorité compétente"),
("paid", "Cession à titre onéreux"),
("other", "Autre"),
]

attribution_type = models.CharField(
max_length=16,
choices=ATTRIBUTION_TYPES,
blank=True,
null=False,
verbose_name="Type d'attribution de l'ADS au titulaire actuel",
)

transaction_identifier = models.CharField(
max_length=64,
blank=True,
null=False,
verbose_name="Numéro d'identification lié au registre des transactions",
help_text="Ne renseignez ce numéro que dans le cas où, au sein de votre commune, vous tenez un registre relatif à l'ensemble des transactions officielles. Si vous ne tenez pas un tel registre, il n'est pas nécessaire de renseigner ce champ.",
)

attribution_reason = models.CharField(
max_length=4096,
blank=True,
null=False,
verbose_name="Raison d'attribution",
help_text="Ce champ est optionnel. Il peut être utilisé pour préciser les raisons de l'attribution de l'ADS au titulaire actuel. Par exemple : « changement du gérant de la société », « achat », …",
)

accepted_cpam = models.BooleanField(
blank=True, null=True, verbose_name="Véhicule conventionné CPAM ?"
)
Expand Down Expand Up @@ -694,6 +615,15 @@ def unique_error_message(self, model_class, unique_check):
verbose_name="Email du titulaire de l'ADS",
)

notes = models.TextField(
blank=True,
null=False,
verbose_name="Notes sur l'ADS",
help_text=(
"Champ libre pour les informations complémentaires utiles (numéro d'enregistrement dans le registre des transactions, informations importantes concernant la délivrance ou la cession de l'ADS, etc…)"
),
)


def get_legal_filename(instance, filename):
now = datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
Expand Down
23 changes: 6 additions & 17 deletions mesads/templates/webpack/pages/ads_register/ads.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,6 @@ <h1>
</div>
</template>

<template x-if="ads_in_use === 'true' && ads_before_2014">
<div x-show="ads_before_2014" x-transition class="fr-input-group">
<!-- ADS attribution type -->
{% include 'form_fields/select.html' with x_model="attribution_type" field=form.attribution_type field_errors=form.errors.attribution_type required=form.fields.attribution_type.required readonly=ads_manager.is_locked %}

<!-- Transaction identifier -->
<template x-if="attribution_type === 'paid'">
{% include 'form_fields/string.html' with x_transition=True field=form.transaction_identifier field_errors=form.errors.transaction_identifier required=form.fields.transaction_identifier.required readonly=ads_manager.is_locked %}
</template>

<!-- ADS attribution reason -->
{% include 'form_fields/string.html' with field=form.attribution_reason field_errors=form.errors.attribution_reason required=form.fields.attribution_reason.required readonly=ads_manager.is_locked %}
</div>
</template>

<!-- Accepted by CPAM -->
<template x-if="ads_in_use === 'true'">
{% include 'form_fields/select.html' with field=form.accepted_cpam field_errors=form.errors.accepted_cpam required=form.fields.accepted_cpam.required readonly=ads_manager.is_locked %}
Expand Down Expand Up @@ -354,6 +339,11 @@ <h1>
</fieldset>
</template>

<fieldset class="mesads-fieldset fr-mb-3w">
<legend>Informations complémentaires</legend>
{% include 'form_fields/textarea.html' with field=form.notes field_errors=form.errors.notes required=form.fields.notes.required %}
</fieldset>

<!-- Submit buttons -->
<div class="fr-input-group">
{% if ads %}
Expand Down Expand Up @@ -384,8 +374,7 @@ <h1>
<script id="data" type="application/json">
{
"ads_creation_date": "{{ form.ads_creation_date.value|str_to_date|date:"Y-m-d"|default:"" }}",
"ads_in_use": "{% if form.ads_in_use.value is True %}true{% elif form.ads_in_use.value is False %}false{% endif %}",
"attribution_type": "{{ form.attribution_type.value }}"
"ads_in_use": "{% if form.ads_in_use.value is True %}true{% elif form.ads_in_use.value is False %}false{% endif %}"
}
</script>
<script src="./ads.ts"></script>
Expand Down
3 changes: 0 additions & 3 deletions mesads/templates/webpack/pages/ads_register/ads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ SetupFormsetFiles();

type DataType = {
ads_creation_date: string;
attribution_type: string;
ads_in_use: string;
};

Expand All @@ -31,8 +30,6 @@ Alpine.data("get_x_data", () => ({

ads_in_use: data.ads_in_use,

attribution_type: data.attribution_type,

extraADSUserForms: 0,
}));

Expand Down

0 comments on commit 97b8b80

Please sign in to comment.