From 5ecaba6449819ab486d26deb448cd3559255014c Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 9 Nov 2023 12:03:09 +0100 Subject: [PATCH] Create amount_display property. Add tests. Update tasks --- lemarche/tenders/models.py | 13 ++++++++++++- lemarche/tenders/tests.py | 14 ++++++++++++++ lemarche/www/tenders/tasks.py | 8 ++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index 149d02be5..dc730dcbe 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -519,6 +519,17 @@ def location_display(self) -> str: # maintain legacy perimeters display return self.perimeters_list_string + @cached_property + def amount_display(self) -> str: + if not self.accept_share_amount: + return "Non renseigné" + elif self.amount_exact: + return f"{self.amount_exact} €" + elif self.amount: + return self.get_amount_display() + else: + return "Non renseigné" + def questions_list(self): return list(self.questions.values("id", "text")) @@ -546,7 +557,7 @@ def cta_card_paragraph_text(self): elif self.kind == tender_constants.KIND_QUOTE: return "Accéder aux coordonnées du client afin de lui envoyer un devis." elif self.kind == tender_constants.KIND_PROJECT and self.response_is_anonymous: - return "Manifestez votre intérêt au client. S’il est intéressé, le client vous recontactera via les coordonnées présentes sur votre fiche commerciale." # noqa + return "Manifestez votre intérêt au client. S'il est intéressé, le client vous recontactera via les coordonnées présentes sur votre fiche commerciale." # noqa elif self.kind == tender_constants.KIND_PROJECT: return "Accéder aux coordonnées du client afin de lui présenter vos services et produits." # just in case diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index 2060a583a..dc51e382b 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -114,6 +114,20 @@ def test_status(self): self.assertTrue(tender_validated_half.is_validated, False) self.assertTrue(tender_validated_full.is_validated, True) + def test_amount_display(self): + tender_with_amount = TenderFactory(amount=tender_constants.AMOUNT_RANGE_0_1, accept_share_amount=True) + tender_with_amount_exact = TenderFactory( + amount=tender_constants.AMOUNT_RANGE_10_15, amount_exact=10000, accept_share_amount=True + ) + tender_dont_share_amount = TenderFactory( + amount=tender_constants.AMOUNT_RANGE_10_15, amount_exact=10000, accept_share_amount=False + ) + tender_no_amount = TenderFactory(amount=None, amount_exact=None, accept_share_amount=True) + self.assertEqual(tender_with_amount.amount_display, "10-15 K€") + self.assertEqual(tender_with_amount_exact.amount_display, "10000 €") + self.assertEqual(tender_dont_share_amount.amount_display, "Non renseigné") + self.assertEqual(tender_no_amount.amount_display, "Non renseigné") + class TenderModelSaveTest(TestCase): def test_set_slug(self): diff --git a/lemarche/www/tenders/tasks.py b/lemarche/www/tenders/tasks.py index 1410c48dd..30f99d918 100644 --- a/lemarche/www/tenders/tasks.py +++ b/lemarche/www/tenders/tasks.py @@ -136,7 +136,7 @@ def send_tender_email_to_siae(tender: Tender, siae: Siae, email_subject: str, em "TENDER_KIND": tender.get_kind_display(), "TENDER_SECTORS": tender.sectors_list_string(), "TENDER_PERIMETERS": tender.location_display, - "TENDER_AMOUNT": tender.amount, + "TENDER_AMOUNT": tender.amount_display, "TENDER_DEADLINE_DATE": date_to_string(tender.deadline_date), "TENDER_URL": f"{get_share_url_object(tender)}?siae_id={siae.id}", } @@ -214,7 +214,7 @@ def send_tender_contacted_reminder_email_to_siae( "TENDER_KIND": tendersiae.tender.get_kind_display(), "TENDER_SECTORS": tendersiae.tender.sectors_list_string(), "TENDER_PERIMETERS": tendersiae.tender.location_display, - "TENDER_AMOUNT": tendersiae.tender.amount, + "TENDER_AMOUNT": tendersiae.tender.amount_display, "TENDER_DEADLINE_DATE": date_to_string(tendersiae.tender.deadline_date), "TENDER_URL": f"{get_share_url_object(tendersiae.tender)}?siae_id={tendersiae.siae.id}&mtm_campaign=relance-esi-contactees", # noqa } @@ -288,7 +288,7 @@ def send_tender_interested_reminder_email_to_siae( "TENDER_KIND": tendersiae.tender.get_kind_display(), "TENDER_SECTORS": tendersiae.tender.sectors_list_string(), "TENDER_PERIMETERS": tendersiae.tender.location_display, - "TENDER_AMOUNT": tendersiae.tender.amount, + "TENDER_AMOUNT": tendersiae.tender.amount_display, "TENDER_DEADLINE_DATE": date_to_string(tendersiae.tender.deadline_date), "TENDER_URL": f"{get_share_url_object(tendersiae.tender)}?siae_id={tendersiae.siae.id}&mtm_campaign=relance-esi-interessees", # noqa } @@ -332,7 +332,7 @@ def send_confirmation_published_email_to_author(tender: Tender, nb_matched_siaes "TENDER_KIND": tender.get_kind_display(), "TENDER_SECTORS": tender.sectors_list_string(), "TENDER_PERIMETERS": tender.location_display, - "TENDER_AMOUNT": tender.amount, + "TENDER_AMOUNT": tender.amount_display, "TENDER_DEADLINE_DATE": date_to_string(tender.deadline_date), "TENDER_NB_MATCH": nb_matched_siaes, "TENDER_URL": get_share_url_object(tender),