Skip to content

Commit

Permalink
Dépôt de besoin : nouveau champ pour overrider le company_name affiché (
Browse files Browse the repository at this point in the history
#905)

* Add field tender.contact_company_name

* Add rule to display tender contact company_name (override author info)

* Add tests
  • Loading branch information
raphodn authored Sep 11, 2023
1 parent 4720d95 commit 903f3b6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lemarche/templates/tenders/_detail_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ <h1>
</div>
</div>
<div class="row text-bold">
<div class="col"
title="Secteurs d'activité : {{ tender.sectors_full_list_string|safe }}">
<div class="col" title="Secteurs d'activité : {{ tender.sectors_full_list_string|safe }}">
<i class="ri-award-line"></i>
{{ tender.sectors_list_string|safe }}
</div>
<div class="col" title="Lieu d'éxécution">
<i class="ri-map-pin-2-line"></i>
{{ tender.location_display|safe }}
</div>
{% if tender.author.company_name %}
<div class="col" title="Type de prestation">
{% if tender.contact_company_name_display %}
<div class="col" title="Entreprise">
<i class="ri-building-4-line"></i>
{{ tender.author.company_name }}
{{ tender.contact_company_name_display }}
</div>
{% endif %}
</div>
Expand Down
4 changes: 2 additions & 2 deletions lemarche/templates/tenders/_detail_contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ <h2>
{{ tender.contact_full_name|safe }}
</div>
{% endif %}
{% if tender.author.company_name %}
{% if tender.contact_company_name_display %}
<div class="col-md-6">
<i class="ri-building-4-line"></i>
{{ tender.author.company_name }}
{{ tender.contact_company_name_display }}
</div>
{% endif %}
{% if tender.can_display_contact_email or source == "alert" and not tender.response_kind_is_only_external %}
Expand Down
22 changes: 22 additions & 0 deletions lemarche/tenders/migrations/0055_tender_contact_company_name.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
13 changes: 13 additions & 0 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down
25 changes: 23 additions & 2 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 903f3b6

Please sign in to comment.