Skip to content

Commit

Permalink
Brevo: on buyer search, add to contact list
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 21, 2024
1 parent c38f242 commit 908196a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
# -- Sendinblue (BREVO)
BREVO_API_KEY = env.str("BREVO_API_KEY", "set-it")
BREVO_CL_SIGNUP_BUYER_ID = env.int("BREVO_CL_SIGNUP_BUYER_ID", 10)
BREVO_CL_BUYER_SEARCH_SIAE_LIST_ID = env.int("BREVO_CL_BUYER_SEARCH_SIAE_LIST_ID", 12)

INBOUND_PARSING_DOMAIN_EMAIL = env.str("INBOUND_PARSING_DOMAIN_EMAIL", "reply.staging.lemarche.inclusion.beta.gouv.fr")

Expand Down
18 changes: 18 additions & 0 deletions lemarche/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,24 @@ def kind_detail_display(self):
def has_siae(self):
return self.siaes.exists()

@property
def is_buyer(self):
return self.kind == self.KIND_BUYER

@property
def is_buyer_pro(self):
return (
self.is_buyer
and self.buyer_kind_detail
and (
self.buyer_kind_detail
not in [
user_constants.BUYER_KIND_DETAIL_PRIVATE_TPE,
user_constants.BUYER_KIND_DETAIL_PUBLIC_ASSOCIATION,
]
)
)

@property
def is_admin(self) -> bool:
return self.kind == self.KIND_ADMIN
Expand Down
3 changes: 2 additions & 1 deletion lemarche/utils/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def add_to_contact_list(user, type: str, source: str = user_constants.SOURCE_SIG
api_hubspot.add_user_to_crm(user)
api_brevo.create_contact(user=user, list_id=settings.BREVO_CL_SIGNUP_BUYER_ID)
elif type == "buyer_search":
contact_list_id = settings.MAILJET_NL_CL_BUYER_SEARCH_SIAE_LIST_ID
# contact_list_id = settings.MAILJET_NL_CL_BUYER_SEARCH_SIAE_LIST_ID
api_brevo.create_contact(user=user, list_id=settings.BREVO_CL_BUYER_SEARCH_SIAE_LIST_ID)
elif type == "buyer_search_traiteur":
contact_list_id = settings.MAILJET_NL_CL_BUYER_SEARCH_SIAE_TRAITEUR_LIST_ID
elif type == "buyer_search_nettoyage":
Expand Down
7 changes: 7 additions & 0 deletions lemarche/www/siaes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def get_filter_form(self):
self.filter_form = SiaeFilterForm(data=self.request.GET, advanced_search=user.is_authenticated)
return self.filter_form

def get(self, request, *args, **kwargs):
user = self.request.user
if user.is_authenticated and user.is_buyer_pro:
if len(self.request.GET.keys()):
add_to_contact_list(self.request.user, "buyer_search")
return super().get(request, *args, **kwargs)

def get_queryset(self):
"""
Filter results.
Expand Down

0 comments on commit 908196a

Please sign in to comment.