Skip to content

Commit

Permalink
Dépôt de besoin : stocker les (futurs) résultats du sondage "avez-vou…
Browse files Browse the repository at this point in the history
…s transactionné ?" envoyé aux structures (#1071)

* TenderSiae: new fields to store SIAE survey results

* Add to admin. Add fieldset
  • Loading branch information
raphodn authored Feb 8, 2024
1 parent 5843c0e commit 8c59339
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 13 deletions.
34 changes: 22 additions & 12 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,23 +717,26 @@ class TenderSiaeSourceFilter(MultiChoice):
@admin.register(TenderSiae, site=admin_site)
class TenderSiaeAdmin(admin.ModelAdmin):
list_display = ["created_at", "siae_with_link", "tender", "source"]
list_filter = [
("source", TenderSiaeSourceFilter),
]

readonly_fields = [
"id",
"created_at",
"updated_at",
readonly_fields = [field for field in TenderSiae.READONLY_FIELDS] + [
"tender",
"siae",
"email_send_date",
"email_link_click_date",
"detail_display_date",
"detail_contact_click_date",
"logs",
"logs_display",
]

list_filter = [
("source", TenderSiaeSourceFilter),
]
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
Expand All @@ -749,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 4.2.9 on 2024-02-07 07:58

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("tenders", "0072_tender_contact_notifications_disabled"),
]

operations = [
migrations.AddField(
model_name="tendersiae",
name="survey_transactioned_amount",
field=models.PositiveIntegerField(
blank=True, null=True, verbose_name="Sondage transaction : montant du besoin"
),
),
migrations.AddField(
model_name="tendersiae",
name="survey_transactioned_answer",
field=models.BooleanField(blank=True, null=True, verbose_name="Sondage transaction : réponse"),
),
migrations.AddField(
model_name="tendersiae",
name="survey_transactioned_answer_date",
field=models.DateTimeField(blank=True, null=True, verbose_name="Sondage transaction : date de réponse"),
),
migrations.AddField(
model_name="tendersiae",
name="survey_transactioned_feedback",
field=models.TextField(blank=True, verbose_name="Sondage transaction : retour d'expérience"),
),
migrations.AddField(
model_name="tendersiae",
name="survey_transactioned_send_date",
field=models.DateTimeField(
blank=True, null=True, verbose_name="Sondage transaction : date d'envoi de l'e-mail"
),
),
]
42 changes: 41 additions & 1 deletion lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,28 @@ 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",
"survey_transactioned_amount",
"survey_transactioned_feedback",
"survey_transactioned_answer_date",
]
FIELDS_STATS_TIMESTAMPS = [
"created_at",
"updated_at",
]
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)

Expand All @@ -876,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)
Expand All @@ -888,6 +910,24 @@ 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
)
survey_transactioned_answer = models.BooleanField(
verbose_name="Sondage transaction : réponse", blank=True, null=True
)
survey_transactioned_amount = models.PositiveIntegerField(
verbose_name="Sondage transaction : montant du besoin", blank=True, null=True
)
survey_transactioned_feedback = models.TextField(
verbose_name="Sondage transaction : retour d'expérience", blank=True
)
survey_transactioned_answer_date = models.DateTimeField(
"Sondage transaction : date de réponse", blank=True, null=True
)

logs = models.JSONField(verbose_name="Logs historiques", editable=False, default=list)

created_at = models.DateTimeField(verbose_name="Date de création", default=timezone.now)
Expand Down

0 comments on commit 8c59339

Please sign in to comment.