Skip to content

Commit

Permalink
Optimisation de requête sur Tender et modification et ajout de tender…
Browse files Browse the repository at this point in the history
….amount_int
  • Loading branch information
chloend committed Nov 7, 2024
1 parent ab337a1 commit 770b422
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lemarche/api/tenders/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from unittest.mock import patch

from django.conf import settings
from django.test import TestCase
from django.urls import reverse

from unittest.mock import patch

from lemarche.perimeters.factories import PerimeterFactory
from lemarche.sectors.factories import SectorFactory
from lemarche.tenders import constants as tender_constants
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_create_contact_call_has_user_buyer_attributes(self, mock_create_contact

self.assertEqual(kwargs["email"], user.email)
self.assertIn(settings.BREVO_CL_SIGNUP_BUYER_ID, kwargs["list_ids"])
self.assertEqual(attributes["MONTANT_BESOIN_ACHETEUR"], tender.amount)
self.assertEqual(attributes["MONTANT_BESOIN_ACHETEUR"], tender.amount_int)
self.assertEqual(attributes["TYPE_BESOIN_ACHETEUR"], tender.kind)

if sectors.exists():
Expand Down
11 changes: 9 additions & 2 deletions lemarche/utils/apis/api_brevo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sib_api_v3_sdk
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from huey.contrib.djhuey import task
from sib_api_v3_sdk.rest import ApiException

Expand Down Expand Up @@ -51,9 +52,10 @@ def create_contact(user, list_id: int, tender=None):
# WHATSAPP, TYPE_ORGANISATION, LIEN_FICHE_COMMERCIALE, TAUX_DE_COMPLETION
}

if tender:
try:
tender = user.tenders.get(id=tender.id)
sectors = tender.sectors.all()
attributes["MONTANT_BESOIN_ACHETEUR"] = tender.amount
attributes["MONTANT_BESOIN_ACHETEUR"] = tender.amount_int
attributes["TYPE_BESOIN_ACHETEUR"] = tender.kind

# Check if there is at least one sector whose tender source is TALLY
Expand All @@ -62,6 +64,11 @@ def create_contact(user, list_id: int, tender=None):
else:
attributes["TYPE_VERTICALE_ACHETEUR"] = None

except ObjectDoesNotExist:
print("L'objet Tender demandé n'existe pas pour cet utilisateur.")
except AttributeError as e:
print(f"Erreur d'attribut : {e}")

new_contact = sib_api_v3_sdk.CreateContact(
email=user.email,
list_ids=[list_id],
Expand Down
2 changes: 1 addition & 1 deletion lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_create_contact_call_has_user_buyer_attributes(self, mock_create_contact

self.assertEqual(kwargs["email"], user.email)
self.assertIn(settings.BREVO_CL_SIGNUP_BUYER_ID, kwargs["list_ids"])
self.assertEqual(attributes["MONTANT_BESOIN_ACHETEUR"], tender.amount)
self.assertEqual(attributes["MONTANT_BESOIN_ACHETEUR"], tender.amount_int)
self.assertEqual(attributes["TYPE_BESOIN_ACHETEUR"], tender.kind)
self.assertIsNone(
attributes["TYPE_VERTICALE_ACHETEUR"], "Expected TYPE_VERTICALE_ACHETEUR to be None for non-TALLY sources"
Expand Down

0 comments on commit 770b422

Please sign in to comment.