From 9a02ec4a89c09c96a8965197d91a360cee958750 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 27 Feb 2024 17:50:21 +0100 Subject: [PATCH] feat(SIAE): nouveau champ 'extra_data' (#1105) * Siae: add new field extra_data * Add to admin --- lemarche/siaes/admin.py | 9 +++++++++ .../siaes/migrations/0072_siae_extra_data.py | 17 +++++++++++++++++ lemarche/siaes/models.py | 10 ++++++++++ 3 files changed, 36 insertions(+) create mode 100644 lemarche/siaes/migrations/0072_siae_extra_data.py diff --git a/lemarche/siaes/admin.py b/lemarche/siaes/admin.py index 7ce35d3e5..6e5d5d84c 100644 --- a/lemarche/siaes/admin.py +++ b/lemarche/siaes/admin.py @@ -187,6 +187,7 @@ class SiaeAdmin(FieldsetsInlineMixin, gis_admin.OSMGeoAdmin): "tender_detail_display_count_annotated_with_link", "tender_detail_contact_click_count_annotated_with_link", "logs_display", + "extra_data_display", "import_raw_object_display", ] ) @@ -324,6 +325,7 @@ class SiaeAdmin(FieldsetsInlineMixin, gis_admin.OSMGeoAdmin): "signup_date", "content_filled_basic_date", "logs_display", + "extra_data_display", ) }, ), @@ -612,6 +614,13 @@ def logs_display(self, siae=None): logs_display.short_description = Siae._meta.get_field("logs").verbose_name + def extra_data_display(self, instance: Siae = None): + if instance: + return pretty_print_readonly_jsonfield(instance.extra_data) + return "-" + + extra_data_display.short_description = Siae._meta.get_field("extra_data").verbose_name + @admin.register(SiaeUserRequest, site=admin_site) class SiaeUserRequestAdmin(admin.ModelAdmin): diff --git a/lemarche/siaes/migrations/0072_siae_extra_data.py b/lemarche/siaes/migrations/0072_siae_extra_data.py new file mode 100644 index 000000000..e6d94a021 --- /dev/null +++ b/lemarche/siaes/migrations/0072_siae_extra_data.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.9 on 2024-02-26 15:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("siaes", "0071_alter_siae_kind"), + ] + + operations = [ + migrations.AddField( + model_name="siae", + name="extra_data", + field=models.JSONField(default=dict, editable=False, verbose_name="Données complémentaires"), + ), + ] diff --git a/lemarche/siaes/models.py b/lemarche/siaes/models.py index d6ea649a1..5a408e21e 100644 --- a/lemarche/siaes/models.py +++ b/lemarche/siaes/models.py @@ -853,6 +853,7 @@ class Siae(models.Model): source = models.CharField( max_length=20, choices=siae_constants.SOURCE_CHOICES, default=siae_constants.SOURCE_STAFF_C4_CREATED ) + extra_data = models.JSONField(verbose_name="Données complémentaires", editable=False, default=dict) import_raw_object = models.JSONField(verbose_name="Donnée JSON brute", editable=False, null=True) created_at = models.DateTimeField(verbose_name="Date de création", default=timezone.now) @@ -1203,6 +1204,10 @@ def sectors_list_string(self, display_max=3): def sectors_full_list_string(self): return self.sectors_list_string(display_max=None) + @property + def brevo_company_id(self): + return self.extra_data.get("brevo_company_id") + @cached_property def stat_view_count_last_3_months(self): try: @@ -1234,6 +1239,11 @@ def get_absolute_url(self): def get_admin_url(self): return get_object_admin_url(self) + def set_brevo_id(self, brevo_company_id, with_save=True): + self.extra_data.update({"brevo_company_id": brevo_company_id}) + if with_save: + self.save() + def set_super_badge(self): update_fields_list = ["super_badge"] siae_super_badge_current_value = self.super_badge