Skip to content

Commit

Permalink
feat(SIAE): nouveau champ 'extra_data' (#1105)
Browse files Browse the repository at this point in the history
* Siae: add new field extra_data

* Add to admin

Release-As: 2024.2.0
  • Loading branch information
raphodn committed Feb 27, 2024
1 parent 03a527f commit 047a321
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lemarche/siaes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
)
Expand Down Expand Up @@ -324,6 +325,7 @@ class SiaeAdmin(FieldsetsInlineMixin, gis_admin.OSMGeoAdmin):
"signup_date",
"content_filled_basic_date",
"logs_display",
"extra_data_display",
)
},
),
Expand Down Expand Up @@ -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):
Expand Down
17 changes: 17 additions & 0 deletions lemarche/siaes/migrations/0072_siae_extra_data.py
Original file line number Diff line number Diff line change
@@ -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"),
),
]
10 changes: 10 additions & 0 deletions lemarche/siaes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 047a321

Please sign in to comment.