diff --git a/lemarche/templates/tenders/_detail_success_contact.html b/lemarche/templates/tenders/_detail_contact_click_confirm_tender_response_is_anonymous.html similarity index 100% rename from lemarche/templates/tenders/_detail_success_contact.html rename to lemarche/templates/tenders/_detail_contact_click_confirm_tender_response_is_anonymous.html diff --git a/lemarche/templates/tenders/_detail_sidebar.html b/lemarche/templates/tenders/_detail_sidebar.html index 949232e35..257a033e8 100644 --- a/lemarche/templates/tenders/_detail_sidebar.html +++ b/lemarche/templates/tenders/_detail_sidebar.html @@ -49,7 +49,10 @@ Besoin d'aide ? contacter le support via le chat en ligne qui se trouve en bas à droite.

- {% elif not siae_has_detail_contact_click_date %} + {% elif siae_has_detail_contact_click_date %} + {% elif siae_has_detail_not_interested_click_date %} + {% include "tenders/_detail_not_interested_click_confirm.html" %} + {% else %} {% include "tenders/_detail_cta.html" with tender=tender user_can_click=True %} {% include "tenders/_detail_cta_cocontracting.html" with tender=tender %} {% include "tenders/_detail_cta_not_interested.html" with tender=tender user_can_click=True %} @@ -57,21 +60,25 @@ {% endif %} {% elif siae_id %} - {% if not siae_has_detail_contact_click_date %} + {% if siae_has_detail_contact_click_date %} + {% elif siae_has_detail_not_interested_click_date %} + {% include "tenders/_detail_not_interested_click_confirm.html" %} + {% else %} {% include "tenders/_detail_cta.html" with tender=tender user_can_click=True siae_id=siae_id %} {% include "tenders/_detail_cta_cocontracting.html" with tender=tender siae_id=siae_id %} {% include "tenders/_detail_cta_not_interested.html" with tender=tender user_can_click=True siae_id=siae_id %} - {% else %} - {% include "tenders/_detail_contact.html" with tender=tender %} {% endif %} {% endif %} {% else %} {% if user.is_authenticated or siae_id %} - {% if not siae_has_detail_contact_click_date %} - {% include "tenders/_detail_cta.html" with tender=tender user_can_click=True siae_id=siae_id tender_response_is_anonymous=True %} + {% if siae_has_detail_contact_click_date %} + {% include "tenders/_detail_contact_click_confirm_tender_response_is_anonymous.html" %} + {% elif siae_has_detail_not_interested_click_date %} + {% include "tenders/_detail_not_interested_click_confirm.html" %} {% else %} - {% include "tenders/_detail_success_contact.html" %} + {% include "tenders/_detail_cta.html" with tender=tender user_can_click=True siae_id=siae_id tender_response_is_anonymous=True %} + {% include "tenders/_detail_cta_not_interested.html" with tender=tender user_can_click=True siae_id=siae_id %} {% endif %} {% endif %} {% endif %} diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index 88c7f611a..0156ad522 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -573,9 +573,13 @@ def setUpTestData(cls): cls.siae_1 = SiaeFactory(name="ZZ ESI") cls.siae_2 = SiaeFactory(name="ABC Insertion") cls.siae_3 = SiaeFactory(name="ABC Insertion bis") + cls.siae_4 = SiaeFactory(name="ESAT 4") + cls.siae_5 = SiaeFactory(name="ESAT 5") cls.siae_user_1 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_1]) cls.siae_user_2 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_2, cls.siae_3]) - cls.siae_user_3 = UserFactory(kind=User.KIND_SIAE) + cls.siae_user_4 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_4]) + cls.siae_user_5 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_5]) + cls.siae_user_without_siae = UserFactory(kind=User.KIND_SIAE) cls.user_buyer_1 = UserFactory(kind=User.KIND_BUYER, company_name="Entreprise Buyer") cls.user_buyer_2 = UserFactory(kind=User.KIND_BUYER) cls.user_partner = UserFactory(kind=User.KIND_PARTNER) @@ -610,6 +614,15 @@ def setUpTestData(cls): detail_display_date=timezone.now(), detail_contact_click_date=timezone.now(), ) + cls.tendersiae_1_4 = TenderSiae.objects.create( + tender=cls.tender_1, + siae=cls.siae_4, + source="EMAIL", + email_send_date=timezone.now(), + email_link_click_date=timezone.now(), + detail_display_date=timezone.now(), + detail_not_interested_click_date=timezone.now(), + ) TenderQuestionFactory(tender=cls.tender_1) cls.tender_2 = TenderFactory( author=cls.user_buyer_1, @@ -633,6 +646,15 @@ def setUpTestData(cls): detail_display_date=timezone.now(), detail_contact_click_date=timezone.now(), ) + cls.tendersiae_3_4 = TenderSiae.objects.create( + tender=cls.tender_3_response_is_anonymous, + siae=cls.siae_4, + source="EMAIL", + email_send_date=timezone.now(), + email_link_click_date=timezone.now(), + detail_display_date=timezone.now(), + detail_not_interested_click_date=timezone.now(), + ) def test_anyone_can_view_sent_tenders(self): for tender in Tender.objects.all(): @@ -774,13 +796,13 @@ def test_tender_author_has_additional_stats(self): self.client.force_login(self.user_buyer_1) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) - self.assertContains(response, "1 prestataire ciblé") + self.assertContains(response, "2 prestataires ciblés") self.assertContains(response, "1 prestataire intéressé") # but hidden for non-author self.client.force_login(self.user_buyer_2) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) - self.assertNotContains(response, "1 prestataire ciblé") + self.assertNotContains(response, "2 prestataires ciblés") self.assertNotContains(response, "1 prestataire intéressé") def test_admin_has_extra_info(self): @@ -810,13 +832,20 @@ def test_tender_contact_display(self): response = self.client.get(url) self.assertContains(response, "Contactez le client dès maintenant") self.assertNotContains(response, "Voir l'appel d'offres") + # siae user not interested + self.client.force_login(self.siae_user_4) + url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Contactez le client dès maintenant") + self.assertNotContains(response, "Voir l'appel d'offres") + self.assertContains(response, "Vous n'êtes pas intéressé par ce besoin") # siae user not concerned - self.client.force_login(self.siae_user_2) + self.client.force_login(self.siae_user_5) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertContains(response, "Voir l'appel d'offres") # siae user without siae - self.client.force_login(self.siae_user_3) + self.client.force_login(self.siae_user_without_siae) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertContains(response, "veuillez d'abord vous") @@ -841,13 +870,21 @@ def test_tender_response_is_anonymous_contact_display(self): self.assertNotContains(response, "Contactez le client dès maintenant") self.assertNotContains(response, "Voir l'appel d'offres") self.assertContains(response, "Votre intérêt a été signalé au client") + # siae user not interested + self.client.force_login(self.siae_user_4) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Contactez le client dès maintenant") + self.assertNotContains(response, "Voir l'appel d'offres") + self.assertNotContains(response, "Votre intérêt a été signalé au client") + self.assertContains(response, "Vous n'êtes pas intéressé par ce besoin") # siae user not concerned - self.client.force_login(self.siae_user_2) + self.client.force_login(self.siae_user_5) url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) response = self.client.get(url) self.assertNotContains(response, "Voir l'appel d'offres") # siae user without siae - self.client.force_login(self.siae_user_3) + self.client.force_login(self.siae_user_without_siae) url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) response = self.client.get(url) self.assertNotContains(response, "veuillez d'abord vous") @@ -879,13 +916,13 @@ def test_tender_outdated_contact_display(self): self.assertNotContains(response, "Contactez le client dès maintenant") self.assertNotContains(response, "Répondre à cette opportunité") # siae user not concerned - self.client.force_login(self.siae_user_2) + self.client.force_login(self.siae_user_5) url = reverse("tenders:detail", kwargs={"slug": tender_2.slug}) response = self.client.get(url) self.assertContains(response, "Clôturé") self.assertNotContains(response, "Répondre à cette opportunité") # siae user without siae - self.client.force_login(self.siae_user_3) + self.client.force_login(self.siae_user_without_siae) url = reverse("tenders:detail", kwargs={"slug": tender_2.slug}) response = self.client.get(url) self.assertContains(response, "Clôturé") @@ -1027,7 +1064,7 @@ def test_tender_cocontracting_display(self): response = self.client.get(url) self.assertNotContains(response, "Répondre en co-traitance ?") # siae user not concerned - self.client.force_login(self.siae_user_2) + self.client.force_login(self.siae_user_5) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertContains(response, "Répondre en co-traitance ?") @@ -1038,7 +1075,7 @@ def test_tender_cocontracting_display(self): response = self.client.get(url) self.assertContains(response, "Répondre en co-traitance ?") # siae user without siae - self.client.force_login(self.siae_user_3) + self.client.force_login(self.siae_user_without_siae) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertNotContains(response, "Répondre en co-traitance ?") @@ -1050,7 +1087,7 @@ def test_tender_cocontracting_display(self): 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.count(), 2 + 1) self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2) self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date) self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date) @@ -1061,42 +1098,42 @@ def test_update_tendersiae_stats_on_tender_view(self): url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertContains(response, "Déjà 1 prestataire inclusif") - # reload anonymous user with ?siae_id= + self.assertContains(response, "Déjà 2 prestataires inclusifs") + # reload anonymous user with ?siae_id= (already in tendersiae) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + f"?siae_id={self.siae_2.id}" response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(self.tender_1.tendersiae_set.count(), 2) # unchanged + self.assertEqual(self.tender_1.tendersiae_set.count(), 3) # unchanged siae_2_email_link_click_date = self.tender_1.tendersiae_set.first().email_link_click_date self.assertIsNotNone(siae_2_email_link_click_date) # email_link_click_date updated self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date) self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date) - self.assertContains(response, "Déjà 2 prestataires inclusifs") + self.assertContains(response, "Déjà 3 prestataires inclusifs") self.assertNotContains(response, "contactez dès maintenant le client") # reload logged in with ?siae_id= (updats detail_display_date, but not email_link_click_date) self.client.force_login(self.siae_user_2) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + f"?siae_id={self.siae_2.id}" response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(self.tender_1.tendersiae_set.count(), 2) # unchanged + self.assertEqual(self.tender_1.tendersiae_set.count(), 3) # unchanged self.assertEqual(self.tender_1.tendersiae_set.first().email_link_click_date, siae_2_email_link_click_date) siae_2_detail_display_date = self.tender_1.tendersiae_set.first().detail_display_date self.assertIsNotNone(siae_2_detail_display_date) # detail_display_date updated self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date) - self.assertContains(response, "Déjà 2 prestataires inclusifs") + self.assertContains(response, "Déjà 3 prestataires inclusifs") self.assertNotContains(response, "contactez dès maintenant le client") # reload (doesn't update detail_display_date) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(self.tender_1.tendersiae_set.count(), 2) # unchanged + self.assertEqual(self.tender_1.tendersiae_set.count(), 3) # unchanged self.assertEqual(self.tender_1.tendersiae_set.first().detail_display_date, siae_2_detail_display_date) - self.assertContains(response, "Déjà 2 prestataires inclusifs") + self.assertContains(response, "Déjà 3 prestataires inclusifs") self.assertNotContains(response, "contactez dès maintenant le client") def test_create_tendersiae_stats_on_tender_view_by_existing_user(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.count(), 2 + 1) self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2) self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date) self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date) @@ -1106,36 +1143,36 @@ def test_create_tendersiae_stats_on_tender_view_by_existing_user(self): # first load anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) - self.assertContains(response, "Déjà 1 prestataire inclusif") + self.assertContains(response, "Déjà 2 prestataires inclusifs") # first load, new user has already 1 siae contacted, we update only this one self.client.force_login(self.siae_user_2) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 1) + self.assertEqual(self.tender_1.tendersiae_set.count(), 2 + 1) self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2) self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date) self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) - self.assertContains(response, "Déjà 2 prestataires inclusifs") + self.assertContains(response, "Déjà 3 prestataires inclusifs") def test_create_tendersiae_stats_on_tender_view_by_new_user(self): - self.assertEqual(self.tender_1.tendersiae_set.count(), 1) - self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_1) - self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) # siae_1 + self.assertEqual(self.tender_1.tendersiae_set.count(), 2) + self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_4) + self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) # siae_4 # first load anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) - self.assertContains(response, "Déjà 1 prestataire inclusif") + self.assertContains(response, "Déjà 2 prestataires inclusifs") # first load, new user has 2 siaes self.client.force_login(self.siae_user_2) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 2) # adds both siae_2 & siae_3 + self.assertEqual(self.tender_1.tendersiae_set.count(), 2 + 2) # adds both siae_2 & siae_3 self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_3) self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date) self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) - self.assertContains(response, "Déjà 3 prestataires inclusifs") + self.assertContains(response, "Déjà 4 prestataires inclusifs") class TenderDetailContactClickStatViewTest(TestCase): diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index 738f4a3c9..62e614376 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -377,6 +377,9 @@ def get_context_data(self, **kwargs): context["siae_has_detail_contact_click_date"] = TenderSiae.objects.filter( tender=self.object, siae_id=int(self.siae_id), detail_contact_click_date__isnull=False ).exists() + context["siae_has_detail_not_interested_click_date"] = TenderSiae.objects.filter( + tender=self.object, siae_id=int(self.siae_id), detail_not_interested_click_date__isnull=False + ).exists() if user.is_authenticated: if user.kind == User.KIND_SIAE: context["siae_has_detail_contact_click_date"] = ( @@ -385,6 +388,12 @@ def get_context_data(self, **kwargs): tender=self.object, siae__in=user.siaes.all(), detail_contact_click_date__isnull=False ).exists() ) + context["siae_has_detail_not_interested_click_date"] = ( + getattr(context, "siae_has_detail_not_interested_click_date", None) + or TenderSiae.objects.filter( + tender=self.object, siae__in=user.siaes.all(), detail_not_interested_click_date__isnull=False + ).exists() + ) if show_nps: context["show_nps"] = True elif user.kind == User.KIND_PARTNER: