diff --git a/lemarche/templates/tenders/_list_item_siae.html b/lemarche/templates/tenders/_list_item_siae.html index f4a75ffbe..fe5bfbeaa 100644 --- a/lemarche/templates/tenders/_list_item_siae.html +++ b/lemarche/templates/tenders/_list_item_siae.html @@ -16,9 +16,9 @@ {% endif %} Disponible jusqu'au : {{ tender.deadline_date|default:"" }} - {% endif %} - {% if not tender.tendersiae_set.first.detail_display_date %} - Nouveau + {% if not tender.tendersiae_set.first.detail_display_date %} + Nouveau + {% endif %} {% endif %}
diff --git a/lemarche/users/models.py b/lemarche/users/models.py index d005d7b63..459cf2f06 100644 --- a/lemarche/users/models.py +++ b/lemarche/users/models.py @@ -1,3 +1,5 @@ +from datetime import datetime + from django.conf import settings from django.contrib.auth.base_user import BaseUserManager from django.contrib.auth.models import AbstractUser @@ -364,9 +366,10 @@ def has_tender_siae(self, tender=None): def tender_siae_unread_count(self): from lemarche.tenders.models import TenderSiae - qs = TenderSiae.objects.filter(siae__in=self.siaes.all(), tender__validated_at__isnull=False).filter( - detail_display_date__isnull=True - ) + limit_date = datetime.today() + qs = TenderSiae.objects.filter( + siae__in=self.siaes.all(), tender__validated_at__isnull=False, tender__deadline_date__gt=limit_date + ).filter(detail_display_date__isnull=True) return qs.count() diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index 4ec6ba13a..dd49dd1b1 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -491,6 +491,10 @@ def setUpTestData(cls): email_send_date=timezone.now(), detail_contact_click_date=timezone.now(), ) + cls.tender_4 = TenderFactory(author=cls.user_buyer_1, perimeters=[perimeter]) + cls.tendersiae_4_1 = TenderSiae.objects.create( + tender=cls.tender_4, siae=cls.siae_1, email_send_date=timezone.now() + ) def test_anonymous_user_cannot_list_tenders(self): url = reverse("tenders:list") @@ -511,8 +515,9 @@ def test_siae_user_should_see_matching_tenders(self): url = reverse("tenders:list") response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(len(response.context["tenders"]), 1) + self.assertEqual(len(response.context["tenders"]), 2) self.assertContains(response, self.tender_3.title) + self.assertContains(response, self.tender_4.title) self.assertContains(response, "Entreprise Buyer") self.assertNotContains(response, "K€") # !accept_share_amount self.assertNotContains(response, "2 prestataires ciblés") # tender_3, but only visible to author @@ -523,7 +528,7 @@ def test_buyer_user_should_only_see_his_tenders(self): url = reverse("tenders:list") response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(len(response.context["tenders"]), 3) + self.assertEqual(len(response.context["tenders"]), 4) self.assertContains(response, "2 prestataires ciblés") # tender_3 self.assertContains(response, "1 prestataire intéressé") # tender_3 self.assertNotContains(response, "Demandes reçues") @@ -551,14 +556,16 @@ def test_siae_user_should_see_unread_badge(self): url = reverse("tenders:list") response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(len(response.context["tenders"]), 1) - # The badge in header + self.assertEqual(len(response.context["tenders"]), 2) + # The badge in header, only one because one is outdated self.assertContains(response, 'Demandes reçues 1') # The badge in tender list - self.assertContains(response, 'Nouveau') + self.assertContains( + response, 'Nouveau', 1 + ) # Open tender detail page - detail_url = reverse("tenders:detail", kwargs={"slug": self.tender_3.slug}) + detail_url = reverse("tenders:detail", kwargs={"slug": self.tender_4.slug}) self.client.get(detail_url) # The badges have disappeared