Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add tasks for send order cancel and order refund emails

IKarbowiak836e24723cc2
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
index 986182447b..78fc582477 100644
--- a/saleor/order/emails.py
+++ b/saleor/order/emails.py
@@ -15,6 +15,8 @@ STAFF_CONFIRM_ORDER_TEMPLATE = "order/staff_confirm_order"
CONFIRM_FULFILLMENT_TEMPLATE = "order/confirm_fulfillment"
UPDATE_FULFILLMENT_TEMPLATE = "order/update_fulfillment"
CONFIRM_PAYMENT_TEMPLATE = "order/payment/confirm_payment"
+ORDER_CANCEl_TEMPLATE = "order/order_cancel"
+ORDER_REFUND_TEMPLATE = "order/order_refund"
def collect_staff_order_notification_data(
@@ -138,3 +140,17 @@ def send_payment_confirmation(order_pk):
"""Send the payment confirmation email."""
email_data = collect_data_for_email(order_pk, CONFIRM_PAYMENT_TEMPLATE)
send_templated_mail(**email_data)
+
+
+def send_order_cancel(order_pk):
+ """Send order cancel email."""
+ email_data = collect_data_for_email(order_pk, ORDER_CANCEl_TEMPLATE)
+ send_templated_mail(**email_data)
+
+
+def send_order_refund(order_pk):
+ """Send order refund email."""
+ email_data = collect_data_for_email(order_pk, ORDER_REFUND_TEMPLATE)
+ send_templated_mail(**email_data)
diff --git a/saleor/order/tests/test_emails.py b/saleor/order/tests/test_emails.py
index 872640a77a..2cf4cc35cd 100644
--- a/saleor/order/tests/test_emails.py
+++ b/saleor/order/tests/test_emails.py
@@ -279,3 +279,55 @@ def test_send_fulfillment_emails_with_tracking_number_as_url(
# Render the email to ensure there is no error
email_connection = get_connection()
email_connection.get_email_message(to=recipients, **expected_call_kwargs)
+
+
[email protected]("saleor.order.emails.send_templated_mail")
+def test_send_email_order_cancel(mocked_templated_email, order, site_settings):
+ # given
+ template = emails.ORDER_CANCEl_TEMPLATE
+
+ # when
+ emails.send_order_cancel(order.pk)
+
+ # then
+ email_data = emails.collect_data_for_email(order.pk, template)
+ recipients = [order.get_customer_email()]
+ expected_call_kwargs = {
+ "context": email_data["context"],
+ "from_email": site_settings.default_from_email,
+ "template_name": template,
+ }
+
+ mocked_templated_email.assert_called_once_with(
+ recipient_list=recipients, **expected_call_kwargs
+ )
+
+ # Render the email to ensure there is no error
+ email_connection = get_connection()
+ email_connection.get_email_message(to=recipients, **expected_call_kwargs)
+
+
[email protected]("saleor.order.emails.send_templated_mail")
+def test_send_email_order_refund(mocked_templated_email, order, site_settings):
+ # given
+ template = emails.ORDER_REFUND_TEMPLATE
+
+ # when
+ emails.send_order_refund(order.pk)
+
+ # then
+ email_data = emails.collect_data_for_email(order.pk, template)
+ recipients = [order.get_customer_email()]
+ expected_call_kwargs = {
+ "context": email_data["context"],
+ "from_email": site_settings.default_from_email,
+ "template_name": template,
+ }
+
+ mocked_templated_email.assert_called_once_with(
+ recipient_list=recipients, **expected_call_kwargs
+ )
+
+ # Render the email to ensure there is no error
+ email_connection = get_connection()
+ email_connection.get_email_message(to=recipients, **expected_call_kwargs)