Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Emails): Besoins : configurer les envois d'e-mails avec TemplateTransactional #1193

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,24 +331,8 @@

# Transactional email templates
# -- tender: siae & partners
MAILJET_TENDERS_SIAE_PRESENTATION_TEMPLATE_ID = env.int("MAILJET_TENDERS_SIAE_PRESENTATION_TEMPLATE_ID", 3679205)
MAILJET_TENDERS_PARTNER_PRESENTATION_TEMPLATE_ID = env.int("MAILJET_TENDERS_PARTNER_PRESENTATION_TEMPLATE_ID", 3868179)
MAILJET_TENDERS_SIAE_CONTACTED_REMINDER_2D_TEMPLATE_ID = env.int(
"MAILJET_TENDERS_SIAE_CONTACTED_REMINDER_2D_TEMPLATE_ID", 4716371
)
MAILJET_TENDERS_SIAE_CONTACTED_REMINDER_3D_TEMPLATE_ID = env.int(
"MAILJET_TENDERS_SIAE_CONTACTED_REMINDER_3D_TEMPLATE_ID", 4716387
)
MAILJET_TENDERS_SIAE_CONTACTED_REMINDER_4D_TEMPLATE_ID = env.int(
"MAILJET_TENDERS_SIAE_CONTACTED_REMINDER_4D_TEMPLATE_ID", 4716426
)
MAILJET_TENDERS_SIAE_INTERESTED_REMINDER_2D_TEMPLATE_ID = env.int(
"MAILJET_TENDERS_SIAE_INTERESTED_REMINDER_2D_TEMPLATE_ID", 4744896
)
# -- tender: author
MAILJET_TENDERS_AUTHOR_CONFIRMATION_VALIDATED_TEMPLATE_ID = env.int(
"MAILJET_TENDERS_AUTHOR_CONFIRMATION_VALIDATED_TEMPLATE_ID", 3896680
)
MAILJET_TENDERS_AUTHOR_SIAE_INTERESTED_1_TEMPLATE_ID = env.int(
"MAILJET_TENDERS_AUTHOR_SIAE_INTERESTED_1_TEMPLATE_ID", 3867188
)
Expand Down
43 changes: 22 additions & 21 deletions lemarche/conversations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def __str__(self):

@property
def get_template_id(self):
if self.is_active and self.source and self.code:
if self.source and self.code:
if self.source == conversation_constants.SOURCE_MAILJET:
return self.mailjet_id
elif self.source == conversation_constants.SOURCE_BREVO:
Expand All @@ -263,23 +263,24 @@ def send_transactional_email(
from_email=settings.DEFAULT_FROM_EMAIL,
from_name=settings.DEFAULT_FROM_NAME,
):
if self.source == conversation_constants.SOURCE_MAILJET:
api_mailjet.send_transactional_email_with_template(
template_id=self.get_template_id,
recipient_email=recipient_email,
recipient_name=recipient_name,
variables=variables,
subject=subject,
from_email=from_email,
from_name=from_name,
)
elif self.source == conversation_constants.SOURCE_BREVO:
api_brevo.send_transactional_email_with_template(
template_id=self.get_template_id,
recipient_email=recipient_email,
recipient_name=recipient_name,
variables=variables,
subject=subject,
from_email=from_email,
from_name=from_name,
)
if self.is_active:
if self.source == conversation_constants.SOURCE_MAILJET:
api_mailjet.send_transactional_email_with_template(
template_id=self.get_template_id,
recipient_email=recipient_email,
recipient_name=recipient_name,
variables=variables,
subject=subject,
from_email=from_email,
from_name=from_name,
)
elif self.source == conversation_constants.SOURCE_BREVO:
api_brevo.send_transactional_email_with_template(
template_id=self.get_template_id,
recipient_email=recipient_email,
recipient_name=recipient_name,
variables=variables,
subject=subject,
from_email=from_email,
from_name=from_name,
)
2 changes: 1 addition & 1 deletion lemarche/conversations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def setUpTestData(cls):
)

def test_get_template_id(self):
self.assertIsNone(self.tt_inactive.get_template_id)
self.assertIsNone(self.tt_active_empty.get_template_id)
self.assertEqual(self.tt_inactive.get_template_id, self.tt_inactive.mailjet_id)
self.assertEqual(self.tt_active_mailjet.get_template_id, self.tt_active_mailjet.mailjet_id)
self.assertEqual(self.tt_active_brevo.get_template_id, self.tt_active_brevo.brevo_id)
4 changes: 4 additions & 0 deletions lemarche/siaes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,10 @@ def contact_short_name(self):
return f"{self.contact_first_name.upper()[:1]}. {self.contact_last_name.upper()}"
return ""

@property
def contact_email_name_display(self):
return self.contact_full_name or self.name_display

@property
def contact_phone_display(self):
return phone_number_display(self.contact_phone)
Expand Down
8 changes: 5 additions & 3 deletions lemarche/www/conversations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

def send_first_email_from_conversation(conv: Conversation):
siae: Siae = conv.siae
from_email = f"{conv.sender_first_name} {conv.sender_last_name} <{conv.sender_email_buyer_encoded}>"
from_name = f"{conv.sender_first_name} {conv.sender_last_name}"
from_email = f"{from_name} <{conv.sender_email_buyer_encoded}>"

sender_company_name = ""
if conv.sender_user and conv.sender_user.company_name:
Expand All @@ -38,7 +39,8 @@ def send_email_from_conversation(
):
if user_kind == Conversation.USER_KIND_SENDER_TO_SIAE:
# from the buyer to the siae
from_email = f"{conv.sender_first_name} {conv.sender_last_name} <{conv.sender_email_buyer_encoded}>"
from_name = f"{conv.sender_first_name} {conv.sender_last_name}"
from_email = f"{from_name} <{conv.sender_email_buyer_encoded}>"
send_mail_async(
email_subject=email_subject,
email_body=email_body + DISCLAIMER_ATTACHMENTS,
Expand All @@ -49,7 +51,7 @@ def send_email_from_conversation(
elif user_kind == Conversation.USER_KIND_SENDER_TO_BUYER:
# from the siae to the buyer
siae: Siae = conv.siae
from_email = f"{siae.contact_full_name} <{conv.sender_email_siae_encoded}>"
from_email = f"{siae.contact_email_name_display} <{conv.sender_email_siae_encoded}>"
send_mail_async(
email_subject=email_subject,
email_body=email_body + DISCLAIMER_ATTACHMENTS,
Expand Down
Loading
Loading