diff --git a/lemarche/templates/tenders/_detail_card.html b/lemarche/templates/tenders/_detail_card.html index ebef2d208..8d113ced4 100644 --- a/lemarche/templates/tenders/_detail_card.html +++ b/lemarche/templates/tenders/_detail_card.html @@ -17,8 +17,7 @@

-
+
{{ tender.sectors_list_string|safe }}
@@ -26,10 +25,10 @@

{{ tender.location_display|safe }}

- {% if tender.author.company_name %} -
+ {% if tender.contact_company_name_display %} +
- {{ tender.author.company_name }} + {{ tender.contact_company_name_display }}
{% endif %}
diff --git a/lemarche/templates/tenders/_detail_contact.html b/lemarche/templates/tenders/_detail_contact.html index 504f41f94..11de4b7fa 100644 --- a/lemarche/templates/tenders/_detail_contact.html +++ b/lemarche/templates/tenders/_detail_contact.html @@ -14,10 +14,10 @@

{{ tender.contact_full_name|safe }}

{% endif %} - {% if tender.author.company_name %} + {% if tender.contact_company_name_display %}
- {{ tender.author.company_name }} + {{ tender.contact_company_name_display }}
{% endif %} {% if tender.can_display_contact_email or source == "alert" and not tender.response_kind_is_only_external %} diff --git a/lemarche/tenders/migrations/0055_tender_contact_company_name.py b/lemarche/tenders/migrations/0055_tender_contact_company_name.py new file mode 100644 index 000000000..f9726a56d --- /dev/null +++ b/lemarche/tenders/migrations/0055_tender_contact_company_name.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.2 on 2023-09-11 10:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("tenders", "0054_tender_survey_transactioned_send_date"), + ] + + operations = [ + migrations.AddField( + model_name="tender", + name="contact_company_name", + field=models.CharField( + blank=True, + help_text="Laisser vide pour afficher le nom de l'entreprise de l'auteur", + max_length=255, + verbose_name="Nom de l'entreprise du contact", + ), + ), + ] diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index 2d306757c..5d60fc41a 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -263,6 +263,12 @@ class Tender(models.Model): max_length=20, blank=True, ) + contact_company_name = models.CharField( + verbose_name="Nom de l'entreprise du contact", + help_text="Laisser vide pour afficher le nom de l'entreprise de l'auteur", + max_length=255, + blank=True, + ) sectors = models.ManyToManyField( "sectors.Sector", @@ -434,6 +440,13 @@ def save(self, *args, **kwargs): def contact_full_name(self) -> str: return f"{self.contact_first_name} {self.contact_last_name}" + def contact_company_name_display(self) -> str: + if self.contact_company_name: + return self.contact_company_name + elif self.author.company_name: + return self.author.company_name + return "" + def sectors_list(self): return self.sectors.form_filter_queryset().values_list("name", flat=True) diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index 416e45a41..9bb11827b 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -441,12 +441,24 @@ def setUpTestData(cls): cls.user_buyer_2 = UserFactory(kind=User.KIND_BUYER) cls.user_partner = UserFactory(kind=User.KIND_PARTNER) cls.user_admin = UserFactory(kind=User.KIND_ADMIN) + sector_1 = SectorFactory(name="Bricolage") + grenoble_perimeter = PerimeterFactory( + name="Grenoble", + kind=Perimeter.KIND_CITY, + insee_code="38185", + department_code="38", + region_code="84", + post_codes=["38000", "38100", "38700"], + # coords=Point(5.7301, 45.1825), + ) cls.tender_1 = TenderFactory( kind=tender_constants.KIND_TENDER, author=cls.user_buyer_1, amount=tender_constants.AMOUNT_RANGE_100_150, accept_share_amount=True, response_kind=[Tender.RESPONSE_KIND_EMAIL], + sectors=[sector_1], + location=grenoble_perimeter, ) cls.tendersiae_1_1 = TenderSiae.objects.create( tender=cls.tender_1, @@ -458,6 +470,7 @@ def setUpTestData(cls): detail_contact_click_date=timezone.now(), ) TenderQuestionFactory(tender=cls.tender_1) + cls.tender_2 = TenderFactory(author=cls.user_buyer_1, contact_company_name="Another company") def test_anyone_can_view_validated_tenders(self): # anonymous @@ -501,8 +514,16 @@ def test_tender_basic_fields_display(self): url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 200) - # tender.author.company_name - self.assertContains(response, "Entreprise Buyer") + # sector + self.assertContains(response, "Bricolage") + # localisation + self.assertContains(response, "Grenoble") + # company_name + self.assertContains(response, "Entreprise Buyer") # tender.author.company_name + url = reverse("tenders:detail", kwargs={"slug": self.tender_2.slug}) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Another company") # tender.contact_company_name def test_tender_questions_display(self): # tender with questions: section should be visible