diff --git a/lemarche/tenders/constants.py b/lemarche/tenders/constants.py index c41537dff..d3fcbfbdc 100644 --- a/lemarche/tenders/constants.py +++ b/lemarche/tenders/constants.py @@ -169,14 +169,19 @@ ] TENDER_SIAE_STATUS_EMAIL_SEND_DATE = "EMAIL_SEND_DATE" +TENDER_SIAE_STATUS_EMAIL_SEND_DATE_DISPLAY = "Contactée" TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE = "EMAIL_LINK_CLICK_DATE" +TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE_DISPLAY = "Cliquée" TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE = "DETAIL_DISPLAY_DATE" +TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE_DISPLAY = "Vue" TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE = "DETAIL_CONTACT_CLICK_DATE" +TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE_DISPLAY = "Intéressée" TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE = "DETAIL_NOT_INTERESTED_CLICK_DATE" +TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE_DISPLAY = "Pas intéressée" TENDER_SIAE_STATUS_CHOICES = ( - (TENDER_SIAE_STATUS_EMAIL_SEND_DATE, "Contactée"), - (TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE, "Cliquée"), - (TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE, "Vue"), - (TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE, "Intéressée"), - (TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE, "Pas intéressée"), + (TENDER_SIAE_STATUS_EMAIL_SEND_DATE, TENDER_SIAE_STATUS_EMAIL_SEND_DATE_DISPLAY), + (TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE, TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE_DISPLAY), + (TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE, TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE_DISPLAY), + (TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE, TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE_DISPLAY), + (TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE, TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE_DISPLAY), ) diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index dbc8771f7..47cc930cc 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -912,20 +912,6 @@ def __str__(self): class TenderSiaeQuerySet(models.QuerySet): - def email_click_reminder(self, gte_days_ago, lt_days_ago): - return ( - self.filter(email_send_date__gte=gte_days_ago) - .filter(email_send_date__lt=lt_days_ago) - .filter(email_link_click_date__isnull=True) - .filter(detail_display_date__isnull=True) - .filter(detail_contact_click_date__isnull=True) - ) - - def detail_contact_click_post_reminder(self, gte_days_ago, lt_days_ago): - return self.filter(detail_contact_click_date__gte=gte_days_ago).filter( - detail_contact_click_date__lt=lt_days_ago - ) - def with_prefetch_related(self): return self.prefetch_related("tender", "siae") @@ -969,6 +955,20 @@ def unread_stats(self, user): .aggregate(**aggregates) ) + def email_click_reminder(self, gte_days_ago, lt_days_ago): + return ( + self.filter(email_send_date__gte=gte_days_ago) + .filter(email_send_date__lt=lt_days_ago) + .filter(email_link_click_date__isnull=True) + .filter(detail_display_date__isnull=True) + .filter(detail_contact_click_date__isnull=True) + ) + + def detail_contact_click_post_reminder(self, gte_days_ago, lt_days_ago): + return self.filter(detail_contact_click_date__gte=gte_days_ago).filter( + detail_contact_click_date__lt=lt_days_ago + ) + class TenderSiae(models.Model): FIELDS_RELATION = [ @@ -1048,15 +1048,15 @@ class Meta: @property def status(self): if self.detail_not_interested_click_date: - return "Pas intéressée" - if self.contact_click_date: - return "Intéressée" + return tender_constants.TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE_DISPLAY + if self.detail_contact_click_date: + return tender_constants.TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE_DISPLAY if self.detail_display_date: - return "Vue" + return tender_constants.TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE_DISPLAY if self.email_link_click_date: - return "Cliquée" + return tender_constants.TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE_DISPLAY if self.email_send_date: - return "Contactée" + return tender_constants.TENDER_SIAE_STATUS_EMAIL_SEND_DATE_DISPLAY class PartnerShareTenderQuerySet(models.QuerySet): diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index 7905d4d2c..33f03f15b 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -775,7 +775,7 @@ def test_tender_partner_is_active(self): self.assertEqual(len(result_2), 4 + 1) -class TenderSiaeModelQuerysetTest(TestCase): +class TenderSiaeModelAndQuerysetTest(TestCase): @classmethod def setUpTestData(cls): cls.user_siae = UserFactory(kind=User.KIND_SIAE) @@ -790,20 +790,20 @@ def setUpTestData(cls): deadline_date=date_tomorrow, kind=tender_constants.KIND_TENDER, ) - TenderSiae.objects.create( + cls.tendersiae_1 = TenderSiae.objects.create( tender=cls.tender_with_siae_1, siae=siae_with_tender_3, email_send_date=date_last_week ) - TenderSiae.objects.create( + cls.tendersiae_2 = TenderSiae.objects.create( tender=cls.tender_with_siae_1, siae=siae_with_tender_4, email_send_date=date_two_days_ago ) - TenderSiae.objects.create( + cls.tendersiae_3 = TenderSiae.objects.create( tender=cls.tender_with_siae_1, siae=siae_with_tender_5, email_send_date=date_two_days_ago, email_link_click_date=date_two_days_ago, detail_contact_click_date=date_two_days_ago, ) - TenderSiae.objects.create( + cls.tendersiae_4 = TenderSiae.objects.create( tender=cls.tender_with_siae_1, siae=siae_with_tender_5, detail_display_date=date_last_week, @@ -813,6 +813,17 @@ def setUpTestData(cls): siaes=[siae_with_tender_2, siae_with_tender_3], deadline_date=date_tomorrow ) + def test_with_status(self): + tendersiae_queryset = TenderSiae.objects.with_status() + self.assertEqual( + tendersiae_queryset.get(id=self.tendersiae_1.id).status_annotated, + tender_constants.TENDER_SIAE_STATUS_EMAIL_SEND_DATE, + ) + self.assertEqual( + tendersiae_queryset.get(id=self.tendersiae_4.id).status_annotated, + tender_constants.TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE, + ) + def test_email_click_reminder(self): lt_days_ago = timezone.now() - timedelta(days=2) gte_days_ago = timezone.now() - timedelta(days=2 + 1) @@ -838,6 +849,16 @@ def test_unread_stats(self): self.assertEqual(stats[f"unread_count_{tender_constants.KIND_QUOTE}_annotated"], 1) self.assertEqual(stats[f"unread_count_{tender_constants.KIND_PROJECT}_annotated"], 0) + def test_status_property(self): + self.assertEqual( + TenderSiae.objects.get(id=self.tendersiae_1.id).status, + tender_constants.TENDER_SIAE_STATUS_EMAIL_SEND_DATE_DISPLAY, + ) + self.assertEqual( + TenderSiae.objects.get(id=self.tendersiae_4.id).status, + tender_constants.TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE_DISPLAY, + ) + class TenderAdminTest(TestCase): def setUp(cls):