diff --git a/lemarche/templates/tenders/detail.html b/lemarche/templates/tenders/detail.html index e919d1bba..45a57f3c8 100644 --- a/lemarche/templates/tenders/detail.html +++ b/lemarche/templates/tenders/detail.html @@ -104,7 +104,7 @@ - {{ tender.siae_detail_display_date_count_all }} prestataire{{ tender.siae_email_send_date_count|pluralize }} qui {{ tender.siae_email_send_date_count|pluralize:'a,ont' }} vu + {{ tender.siae_email_link_click_date_or_detail_display_date_count }} prestataire{{ tender.siae_email_link_click_date_or_detail_display_date_count|pluralize }} qui {{ tender.siae_email_link_click_date_or_detail_display_date_count|pluralize:'a,ont' }} vu @@ -113,11 +113,11 @@ {% endif %} {% else %} {% if not tender.deadline_date_outdated %} - {% if tender.siae_detail_display_date_count_all > 0 %} + {% if tender.siae_email_link_click_date_or_detail_display_date_count > 0 %} {% endif %} diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index 4a4119d62..e2cc5286b 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -133,6 +133,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): # "siae_email_send_count_with_link", "siae_email_link_click_count_with_link", "siae_detail_display_count_with_link", + # "siae_email_link_click_or_detail_display_count_with_link", "siae_detail_contact_click_count_with_link", "siae_transactioned", "created_at", @@ -176,6 +177,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): "siae_email_send_count_with_link", "siae_email_link_click_count_with_link", "siae_detail_display_count_with_link", + "siae_email_link_click_or_detail_display_count_with_link", "siae_detail_contact_click_count_with_link", "logs_display", "extra_data_display", @@ -281,6 +283,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): "siae_email_send_count_with_link", "siae_email_link_click_count_with_link", "siae_detail_display_count_with_link", + "siae_email_link_click_or_detail_display_count_with_link", "siae_detail_contact_click_count_with_link", ) }, @@ -446,6 +449,20 @@ def siae_detail_display_count_with_link(self, tender): siae_detail_display_count_with_link.short_description = "S. vues" siae_detail_display_count_with_link.admin_order_field = "siae_detail_display_count" + def siae_email_link_click_or_detail_display_count_with_link(self, tender): + url = ( + reverse("admin:siaes_siae_changelist") + + f"?tenders__in={tender.id}&tendersiae__detail_display_date__isnull=False" + ) + return format_html( + f'{getattr(tender, "siae_email_link_click_or_detail_display_count", 0)}' + ) + + siae_email_link_click_or_detail_display_count_with_link.short_description = "S. cliquées ou vues" + siae_email_link_click_or_detail_display_count_with_link.admin_order_field = ( + "siae_email_link_click_or_detail_display_count" + ) + def siae_detail_contact_click_count_with_link(self, tender): url = ( reverse("admin:siaes_siae_changelist") diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index 3a75491c2..ca82050d7 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -113,6 +113,17 @@ def with_siae_stats(self): When(tendersiae__detail_display_date__isnull=False, then=1), default=0, output_field=IntegerField() ) ), + siae_email_link_click_or_detail_display_count=Sum( + Case( + When( + Q(tendersiae__detail_display_date__isnull=False) + | Q(tendersiae__detail_display_date__isnull=False), + then=1, + ), + default=0, + output_field=IntegerField(), + ) + ), siae_detail_contact_click_count=Sum( Case( When(tendersiae__detail_contact_click_date__isnull=False, then=1), @@ -555,21 +566,16 @@ def hubspot_deal_id(self): def siae_detail_display_date_count(self): return self.tendersiae_set.filter(detail_display_date__isnull=False).count() - @property - def siae_detail_display_date_count_all(self): - """ - Return all siae that have seen the tender (via e-mail or link or both) - """ - return ( - self.tendersiae_set.filter(Q(email_link_click_date__isnull=False) | Q(detail_display_date__isnull=False)) - .distinct() - .count() - ) - @property def siae_email_send_date_count(self): return self.tendersiae_set.filter(email_send_date__isnull=False).count() + @property + def siae_email_link_click_date_or_detail_display_date_count(self): + return self.tendersiae_set.filter( + Q(email_link_click_date__isnull=False) | Q(detail_display_date__isnull=False) + ).count() + @property def siae_detail_contact_click_date_count(self): return self.tendersiae_set.filter(detail_contact_click_date__isnull=False).count() diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index c4ac38b73..8f84d22a3 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -310,6 +310,7 @@ def test_with_siae_stats_queryset(self): self.assertEqual(tender_with_siae_1.siae_email_send_count, 4) self.assertEqual(tender_with_siae_1.siae_email_link_click_count, 3) self.assertEqual(tender_with_siae_1.siae_detail_display_count, 2) + self.assertEqual(tender_with_siae_1.siae_email_link_click_or_detail_display_count, 2) self.assertEqual(tender_with_siae_1.siae_detail_contact_click_count, 1) self.assertEqual(tender_with_siae_1.siae_detail_contact_click_since_last_seen_date_count, 1) tender_with_siae_2 = Tender.objects.with_siae_stats().filter(id=self.tender_with_siae_2.id).first() @@ -317,6 +318,7 @@ def test_with_siae_stats_queryset(self): self.assertEqual(tender_with_siae_2.siae_count, 1) self.assertEqual(tender_with_siae_2.siae_email_send_count, 1) self.assertEqual(tender_with_siae_2.siae_detail_display_count, 1) + self.assertEqual(tender_with_siae_2.siae_email_link_click_or_detail_display_count, 1) self.assertEqual(tender_with_siae_2.siae_detail_contact_click_count, 1) self.assertEqual(tender_with_siae_2.siae_detail_contact_click_since_last_seen_date_count, 1) tender_without_siae = Tender.objects.with_siae_stats().filter(id=self.tender_without_siae.id).first() @@ -324,6 +326,7 @@ def test_with_siae_stats_queryset(self): self.assertEqual(tender_without_siae.siae_count, 0) self.assertEqual(tender_without_siae.siae_email_send_count, 0) self.assertEqual(tender_without_siae.siae_detail_display_count, 0) + self.assertEqual(tender_without_siae.siae_email_link_click_or_detail_display_count, 0) self.assertEqual(tender_without_siae.siae_detail_contact_click_count, 0) self.assertEqual(tender_without_siae.siae_detail_contact_click_since_last_seen_date_count, 0) @@ -367,6 +370,7 @@ def test_with_deadline_date_is_outdated_queryset(self): # self.assertEqual(tender_with_siae_1.siae_email_send_count, 4) # self.assertEqual(tender_with_siae_1.siae_email_link_click_count, 3) # self.assertEqual(tender_with_siae_1.siae_detail_display_count, 2) + # self.assertEqual(tender_with_siae_1.siae_email_link_click_or_detail_display_count, 2) # self.assertEqual(tender_with_siae_1.siae_detail_contact_click_count, 1) # self.assertEqual(tender_with_siae_1.siae_detail_contact_click_since_last_seen_date_count, 1) diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index 02a8e2694..c0108ddd6 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -613,10 +613,10 @@ def test_update_tendersiae_stats_on_tender_view(self): self.tender_1.siaes.add(self.siae_2) self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 1) self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2) - self.assertEqual(self.tender_1.tendersiae_set.last().siae, self.siae_1) self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date) self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date) - self.assertIsNotNone(self.tender_1.tendersiae_set.last().email_link_click_date) # siae_1 + self.assertEqual(self.tender_1.tendersiae_set.last().siae, self.siae_1) + self.assertIsNotNone(self.tender_1.tendersiae_set.last().email_link_click_date) self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date) # first load anonymous url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})