diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index 457ebb94a..7792d6e2a 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -724,9 +724,20 @@ class TenderSiaeAdmin(admin.ModelAdmin): readonly_fields = [field for field in TenderSiae.READONLY_FIELDS] + [ "tender", "siae", - "logs", + "logs_display", ] + fieldsets = ( + ( + None, + {"fields": ("tender", "siae", "source", "found_with_ai")}, + ), + ("Mise en relation", {"fields": TenderSiae.FIELDS_RELATION}), + ("Transaction ?", {"fields": TenderSiae.FIELDS_SURVEY_TRANSACTIONED}), + ("Stats", {"fields": ("logs_display",)}), + ("Dates", {"fields": ("created_at", "updated_at")}), + ) + def has_add_permission(self, request): return False @@ -741,3 +752,10 @@ def siae_with_link(self, tendersiae_list): siae_with_link.short_description = "Structure" siae_with_link.admin_order_field = "siae" + + def logs_display(self, tender=None): + if tender: + return pretty_print_readonly_jsonfield(tender.logs) + return "-" + + logs_display.short_description = Tender._meta.get_field("logs").verbose_name diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index 7d430c9c0..e2f4a94fc 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -866,6 +866,15 @@ def __str__(self): class TenderSiae(models.Model): + FIELDS_RELATION = [ + "email_send_date", + "email_link_click_date", + "detail_display_date", + "detail_contact_click_date", + "detail_cocontracting_click_date", + "detail_not_interested_click_date", + "detail_not_interested_feedback", + ] FIELDS_SURVEY_TRANSACTIONED = [ "survey_transactioned_send_date", "survey_transactioned_answer", @@ -874,16 +883,10 @@ class TenderSiae(models.Model): "survey_transactioned_answer_date", ] FIELDS_STATS_TIMESTAMPS = [ - "email_send_date", - "email_link_click_date", - "detail_display_date", - "detail_contact_click_date", - "detail_cocontracting_click_date", - "detail_not_interested_click_date", "created_at", "updated_at", ] - READONLY_FIELDS = FIELDS_SURVEY_TRANSACTIONED + FIELDS_STATS_TIMESTAMPS + READONLY_FIELDS = FIELDS_RELATION + FIELDS_SURVEY_TRANSACTIONED + FIELDS_STATS_TIMESTAMPS tender = models.ForeignKey("tenders.Tender", verbose_name="Besoin d'achat", on_delete=models.CASCADE) siae = models.ForeignKey("siaes.Siae", verbose_name="Structure", on_delete=models.CASCADE) @@ -895,7 +898,7 @@ class TenderSiae(models.Model): ) found_with_ai = models.BooleanField("Trouvé par l'IA", default=False) - # stats + # stats: relation email_send_date = models.DateTimeField("Date d'envoi de l'e-mail", blank=True, null=True) email_link_click_date = models.DateTimeField("Date de clic sur le lien dans l'e-mail", blank=True, null=True) detail_display_date = models.DateTimeField("Date de visualisation du besoin", blank=True, null=True) @@ -908,6 +911,7 @@ class TenderSiae(models.Model): detail_not_interested_click_date = models.DateTimeField("Date de clic sur Pas intéressé", blank=True, null=True) detail_not_interested_feedback = models.TextField(verbose_name="Clic sur Pas intéréssé : explication", blank=True) + # stats: transaction survey_transactioned_send_date = models.DateTimeField( verbose_name="Sondage transaction : date d'envoi de l'e-mail", blank=True, null=True )