From 97b8b80a1713b6d94eac2afe5fbcff7e6c7100d3 Mon Sep 17 00:00:00 2001 From: Julien Castets Date: Thu, 1 Aug 2024 19:32:13 +0200 Subject: [PATCH] Remove transaction identifier, attribution type and attribution reason --- mesads/app/admin/ads.py | 1 - mesads/app/forms.py | 4 +- mesads/app/management/commands/import_ads.py | 5 -- .../import_last_update_file_from_paris.py | 15 +--- mesads/app/migrations/0085_ads_notes.py | 56 ++++++++++++ ...ibution_type_empty_for_new_ads_and_more.py | 36 ++++++++ mesads/app/models.py | 88 ++----------------- .../webpack/pages/ads_register/ads.html | 23 ++--- .../webpack/pages/ads_register/ads.ts | 3 - 9 files changed, 110 insertions(+), 121 deletions(-) create mode 100644 mesads/app/migrations/0085_ads_notes.py create mode 100644 mesads/app/migrations/0086_remove_ads_attribution_type_empty_for_new_ads_and_more.py diff --git a/mesads/app/admin/ads.py b/mesads/app/admin/ads.py index 5dd6d52..dc101b2 100644 --- a/mesads/app/admin/ads.py +++ b/mesads/app/admin/ads.py @@ -170,7 +170,6 @@ def has_delete_permission(self, request, obj=None): ADSPeriodListFilter, "adsuser__status", ADSUsersCount, - "attribution_type", "accepted_cpam", ] diff --git a/mesads/app/forms.py b/mesads/app/forms.py index 7cf6fcd..7e30193 100644 --- a/mesads/app/forms.py +++ b/mesads/app/forms.py @@ -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", @@ -105,6 +102,7 @@ class Meta: "owner_phone", "owner_mobile", "owner_email", + "notes", ) def __init__(self, epci=None, *args, **kwargs): diff --git a/mesads/app/management/commands/import_ads.py b/mesads/app/management/commands/import_ads.py index a17f47c..5f5bcf9 100644 --- a/mesads/app/management/commands/import_ads.py +++ b/mesads/app/management/commands/import_ads.py @@ -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 diff --git a/mesads/app/management/commands/import_last_update_file_from_paris.py b/mesads/app/management/commands/import_last_update_file_from_paris.py index 56e2839..1929262 100644 --- a/mesads/app/management/commands/import_last_update_file_from_paris.py +++ b/mesads/app/management/commands/import_last_update_file_from_paris.py @@ -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"] diff --git a/mesads/app/migrations/0085_ads_notes.py b/mesads/app/migrations/0085_ads_notes.py new file mode 100644 index 0000000..36ea235 --- /dev/null +++ b/mesads/app/migrations/0085_ads_notes.py @@ -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), + ] diff --git a/mesads/app/migrations/0086_remove_ads_attribution_type_empty_for_new_ads_and_more.py b/mesads/app/migrations/0086_remove_ads_attribution_type_empty_for_new_ads_and_more.py new file mode 100644 index 0000000..2b38663 --- /dev/null +++ b/mesads/app/migrations/0086_remove_ads_attribution_type_empty_for_new_ads_and_more.py @@ -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", + ), + ] diff --git a/mesads/app/models.py b/mesads/app/models.py index 5892923..83b2441 100644 --- a/mesads/app/models.py +++ b/mesads/app/models.py @@ -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 @@ -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 ?" ) @@ -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") diff --git a/mesads/templates/webpack/pages/ads_register/ads.html b/mesads/templates/webpack/pages/ads_register/ads.html index 90ee0ad..b3a5438 100644 --- a/mesads/templates/webpack/pages/ads_register/ads.html +++ b/mesads/templates/webpack/pages/ads_register/ads.html @@ -147,21 +147,6 @@

- - +
+ Informations complémentaires + {% include 'form_fields/textarea.html' with field=form.notes field_errors=form.errors.notes required=form.fields.notes.required %} +
+
{% if ads %} @@ -384,8 +374,7 @@

diff --git a/mesads/templates/webpack/pages/ads_register/ads.ts b/mesads/templates/webpack/pages/ads_register/ads.ts index 7000cfa..4bddb54 100644 --- a/mesads/templates/webpack/pages/ads_register/ads.ts +++ b/mesads/templates/webpack/pages/ads_register/ads.ts @@ -5,7 +5,6 @@ SetupFormsetFiles(); type DataType = { ads_creation_date: string; - attribution_type: string; ads_in_use: string; }; @@ -31,8 +30,6 @@ Alpine.data("get_x_data", () => ({ ads_in_use: data.ads_in_use, - attribution_type: data.attribution_type, - extraADSUserForms: 0, }));