Skip to content

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

Migrate order emails to plugin. Unify the email payload structure (#6382)

Maciej Korycinskiafe3f7d18365
diff --git a/saleor/account/notifications.py b/saleor/account/notifications.py
index 55b0c89f59..3cafc1764f 100644
--- a/saleor/account/notifications.py
+++ b/saleor/account/notifications.py
@@ -19,72 +19,70 @@ def get_default_user_payload(user: User):
def send_user_password_reset_notification(redirect_url, user, manager):
"""Trigger sending a password reset notification for the given user."""
- user_payload = get_default_user_payload(user)
- user_payload.update(
- {
- "token": default_token_generator.make_token(user),
- "redirect_url": redirect_url,
- }
- )
+ user_payload = {
+ "user": get_default_user_payload(user),
+ "recipient_email": user.email,
+ "token": default_token_generator.make_token(user),
+ "redirect_url": redirect_url,
+ }
manager.notify(NotifyEventType.ACCOUNT_PASSWORD_RESET, payload=user_payload)
def send_account_confirmation(user, redirect_url, manager):
"""Trigger sending an account confirmation notification for the given user."""
- user_payload = get_default_user_payload(user)
- user_payload.update(
- {
- "token": default_token_generator.make_token(user),
- "redirect_url": redirect_url,
- }
- )
- manager.notify(NotifyEventType.ACCOUNT_CONFIRMATION, payload=user_payload)
+
+ payload = {
+ "user": get_default_user_payload(user),
+ "recipient_email": user.email,
+ "token": default_token_generator.make_token(user),
+ "redirect_url": redirect_url,
+ }
+ manager.notify(NotifyEventType.ACCOUNT_CONFIRMATION, payload=payload)
def send_request_user_change_email_notification(
redirect_url, user, new_email, token, manager
):
"""Trigger sending a notification change email for the given user."""
- user_payload = get_default_user_payload(user)
- user_payload.update(
- {
- "old_email": user.email,
- "new_email": new_email,
- "redirect_url": redirect_url,
- "token": token,
- }
- )
- manager.notify(NotifyEventType.ACCOUNT_CHANGE_EMAIL_REQUEST, payload=user_payload)
+ payload = {
+ "user": get_default_user_payload(user),
+ "recipient_email": new_email,
+ "old_email": user.email,
+ "new_email": new_email,
+ "redirect_url": redirect_url,
+ "token": token,
+ }
+ manager.notify(NotifyEventType.ACCOUNT_CHANGE_EMAIL_REQUEST, payload=payload)
def send_user_change_email_notification(recipient_email, user, manager):
"""Trigger sending a email change notification for the given user."""
- user_payload = get_default_user_payload(user)
- user_payload["old_email"] = recipient_email
- manager.notify(NotifyEventType.ACCOUNT_CHANGE_EMAIL_CONFIRM, payload=user_payload)
+ payload = {
+ "user": get_default_user_payload(user),
+ "recipient_email": recipient_email,
+ }
+ manager.notify(NotifyEventType.ACCOUNT_CHANGE_EMAIL_CONFIRM, payload=payload)
def send_account_delete_confirmation_notification(redirect_url, user, manager):
"""Trigger sending a account delete notification for the given user."""
- user_payload = get_default_user_payload(user)
- user_payload.update(
- {
- "token": default_token_generator.make_token(user),
- "redirect_url": redirect_url,
- }
- )
- manager.notify(NotifyEventType.ACCOUNT_DELETE, payload=user_payload)
+ payload = {
+ "user": get_default_user_payload(user),
+ "recipient_email": user.email,
+ "token": default_token_generator.make_token(user),
+ "redirect_url": redirect_url,
+ }
+ manager.notify(NotifyEventType.ACCOUNT_DELETE, payload=payload)
def send_set_password_notification(redirect_url, user, manager, staff=False):
"""Trigger sending a set password notification for the given customer/staff."""
- user_payload = get_default_user_payload(user)
- user_payload.update(
- {
- "token": default_token_generator.make_token(user),
- "redirect_url": redirect_url,
- }
- )
+ user_payload = {
+ "user": get_default_user_payload(user),
+ "token": default_token_generator.make_token(user),
+ "redirect_url": redirect_url,
+ "recipient_email": user.email,
+ }
if staff:
event = NotifyEventType.ACCOUNT_SET_STAFF_PASSWORD
else:
diff --git a/saleor/account/templatetags/i18n_address_tags.py b/saleor/account/templatetags/i18n_address_tags.py
index 42c69342b4..86a9fa5dab 100644
--- a/saleor/account/templatetags/i18n_address_tags.py
+++ b/saleor/account/templatetags/i18n_address_tags.py
@@ -7,7 +7,9 @@ register = template.Library()
@register.inclusion_tag("formatted_address.html")
def format_address(address, include_phone=True, inline=False, latin=False):
- address_data = address.as_data()
+ address_data = address
+ if not isinstance(address, dict):
+ address_data = address.as_data()
address_data["name"] = (
pgettext("Address data", "%(first_name)s %(last_name)s") % address_data
)
@@ -16,6 +18,7 @@ def format_address(address, include_phone=True, inline=False, latin=False):
"Address data", "%(street_address_1)s\n" "%(street_address_2)s" % address_data
)
address_lines = i18naddress.format_address(address_data, latin).split("\n")
- if include_phone and address.phone:
- address_lines.append(address.phone)
+ phone = address_data.get("phone")
+ if include_phone and phone:
+ address_lines.append(phone)
return {"address_lines": address_lines, "inline": inline}
diff --git a/saleor/account/tests/test_notifications.py b/saleor/account/tests/test_notifications.py
index fdd68c857e..34c022631e 100644
--- a/saleor/account/tests/test_notifications.py
+++ b/saleor/account/tests/test_notifications.py
@@ -20,15 +20,14 @@ def test_send_email_request_change(mocked_notify, site_settings, customer_user):
redirect_url, customer_user, new_email, token, manager
)
- expected_payload = get_default_user_payload(customer_user)
- expected_payload.update(
- {
- "old_email": customer_user.email,
- "new_email": new_email,
- "redirect_url": redirect_url,
- "token": token,
- }
- )
+ expected_payload = {
+ "user": get_default_user_payload(customer_user),
+ "old_email": customer_user.email,
+ "new_email": new_email,
+ "redirect_url": redirect_url,
+ "recipient_email": new_email,
+ "token": token,
+ }
mocked_notify.assert_called_once_with(
UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_REQUEST, payload=expected_payload
@@ -43,8 +42,10 @@ def test_send_email_changed_notification(mocked_notify, site_settings, customer_
old_email, customer_user, get_plugins_manager()
)
- expected_payload = get_default_user_payload(customer_user)
- expected_payload.update({"old_email": old_email})
+ expected_payload = {
+ "user": get_default_user_payload(customer_user),
+ "recipient_email": old_email,
+ }
mocked_notify.assert_called_once_with(
UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_CONFIRM, payload=expected_payload
diff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.py
index d278323a46..8b898b7bc9 100644
--- a/saleor/checkout/complete_checkout.py
+++ b/saleor/checkout/complete_checkout.py
@@ -26,8 +26,8 @@ from ..discount.utils import (
remove_voucher_usage_by_customer,
)
from ..order.actions import order_created
-from ..order.emails import send_order_confirmation, send_staff_order_confirmation
from ..order.models import Order, OrderLine
+from ..order.notifications import send_order_confirmation, send_staff_order_confirmation
from ..payment import PaymentError, gateway
from ..payment.models import Payment, Transaction
from ..payment.utils import store_customer_id
@@ -273,12 +273,16 @@ def _create_order(*, checkout: Checkout, order_data: dict, user: User) -> Order:
transaction.on_commit(lambda: order_created(order=order, user=user))
+ # FIXME manager should be passed directly from the info.context.
+ # This should be fixed after we will improve the checkout performance
+ manager = get_plugins_manager()
# Send the order confirmation email
transaction.on_commit(
- lambda: send_order_confirmation.delay(order.pk, checkout.redirect_url, user.pk)
+ lambda: send_order_confirmation(order, checkout.redirect_url, user, manager)
)
+ # TODO we can drop it and subscribe admin and user email plugins to the same event
transaction.on_commit(
- lambda: send_staff_order_confirmation.delay(order.pk, checkout.redirect_url)
+ lambda: send_staff_order_confirmation(order, checkout.redirect_url, manager)
)
return order
diff --git a/saleor/core/notify_events.py b/saleor/core/notify_events.py
index faae439bb3..64a86ec823 100644
--- a/saleor/core/notify_events.py
+++ b/saleor/core/notify_events.py
@@ -6,6 +6,12 @@ class UserNotifyEvent:
ACCOUNT_DELETE = "account_delete"
ACCOUNT_SET_CUSTOMER_PASSWORD = "account_set_customer_password"
INVOICE_READY = "invoice_ready"
+ ORDER_CONFIRMATION = "order_confirmation"
+ ORDER_FULFILLMENT_CONFIRMATION = "order_fulfillment_confirmation"
+ ORDER_FULFILLMENT_UPDATE = "order_fulfillment_update"
+ ORDER_PAYMENT_CONFIRMATION = "order_payment_confirmation"
+ ORDER_CANCELED = "order_canceled"
+ ORDER_REFUND_CONFIRMATION = "order_refund_confirmation"
CHOICES = [
ACCOUNT_CONFIRMATION,
@@ -15,6 +21,12 @@ class UserNotifyEvent:
ACCOUNT_DELETE,
ACCOUNT_SET_CUSTOMER_PASSWORD,
INVOICE_READY,
+ ORDER_CONFIRMATION,
+ ORDER_FULFILLMENT_CONFIRMATION,
+ ORDER_FULFILLMENT_UPDATE,
+ ORDER_PAYMENT_CONFIRMATION,
+ ORDER_CANCELED,
+ ORDER_REFUND_CONFIRMATION,
]
@@ -22,11 +34,13 @@ class AdminNotifyEvent:
ACCOUNT_SET_STAFF_PASSWORD = "account_set_staff_password"
CSV_PRODUCT_EXPORT_SUCCESS = "csv_export_products_success"
CSV_EXPORT_FAILED = "csv_export_failed"
+ STAFF_ORDER_CONFIRMATION = "staff_order_confirmation"
CHOICES = [
ACCOUNT_SET_STAFF_PASSWORD,
CSV_PRODUCT_EXPORT_SUCCESS,
CSV_EXPORT_FAILED,
+ STAFF_ORDER_CONFIRMATION,
]
diff --git a/saleor/core/templatetags/taxed_prices.py b/saleor/core/templatetags/taxed_prices.py
index b61f2474f6..9cc7e6b069 100644
--- a/saleor/core/templatetags/taxed_prices.py
+++ b/saleor/core/templatetags/taxed_prices.py
@@ -1,11 +1,25 @@
from django import template
-from prices import MoneyRange, TaxedMoney, TaxedMoneyRange
+from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange
from ...core.taxes import get_display_price
register = template.Library()
[email protected]_tag("price.html", takes_context=True)
+def price_amount(context, net_amount, gross_amount, currency, display_gross, html=True):
+ amount = net_amount
+ if display_gross:
+ amount = gross_amount
+ if not currency:
+ currency = context.get("currency")
+ return {
+ "price": Money(amount=amount, currency=currency),
+ "is_range": False,
+ "html": html,
+ }
+
+
@register.inclusion_tag("price.html", takes_context=True)
def price(context, base, display_gross=None, html=True):
if isinstance(base, (TaxedMoney, TaxedMoneyRange)):
diff --git a/saleor/core/tests/test_asynchronous_tasks.py b/saleor/core/tests/test_asynchronous_tasks.py
deleted file mode 100644
index 1937c375e2..0000000000
--- a/saleor/core/tests/test_asynchronous_tasks.py
+++ /dev/null
@@ -1,14 +0,0 @@
-import pytest
-
-from ...order.emails import send_order_confirmation, send_payment_confirmation
-
-
-def test_email_sending_asynchronously(
- transactional_db, celery_app, celery_worker, order_with_lines
-):
- redirect_url = "https://www.example.com"
- order = send_order_confirmation.delay(order_with_lines.pk, redirect_url)
- payment = send_payment_confirmation.delay(order_with_lines.pk)
- order.get()
- payment.get()
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index aa52756a0f..194c3f1eb2 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -424,8 +424,8 @@ def create_fake_user(save=True):
# We don't want to spam the console with payment confirmations sent to
# fake customers.
-@patch("saleor.order.emails.send_payment_confirmation.delay")
-def create_fake_payment(mock_email_confirmation, order):
+@patch("saleor.plugins.manager.PluginsManager.notify")
+def create_fake_payment(mock_notify, order):
payment = create_payment(
gateway="mirumee.payments.dummy",
customer_ip_address=fake.ipv4(),
diff --git a/saleor/csv/notifications.py b/saleor/csv/notifications.py
index 6f90f36873..ba4b7a24da 100644
--- a/saleor/csv/notifications.py
+++ b/saleor/csv/notifications.py
@@ -26,8 +26,11 @@ def get_default_export_payload(export_file: "ExportFile") -> dict:
def send_export_download_link_notification(export_file: "ExportFile"):
"""Call PluginManager.notify to trigger the notification for success export."""
- payload = get_default_export_payload(export_file)
- payload["csv_link"] = build_absolute_uri(export_file.content_file.url)
+ payload = {
+ "export": get_default_export_payload(export_file),
+ "csv_link": build_absolute_uri(export_file.content_file.url),
+ "recipient_email": export_file.user.email if export_file.user else None,
+ }
manager = get_plugins_manager()
manager.notify(NotifyEventType.CSV_PRODUCT_EXPORT_SUCCESS, payload)
@@ -36,7 +39,10 @@ def send_export_download_link_notification(export_file: "ExportFile"):
def send_export_failed_info(export_file: "ExportFile"):
"""Call PluginManager.notify to trigger the notification for failed export."""
- payload = get_default_export_payload(export_file)
+ payload = {
+ "export": get_default_export_payload(export_file),
+ "recipient_email": export_file.user.email if export_file.user else None,
+ }
manager = get_plugins_manager()
manager.notify(NotifyEventType.CSV_EXPORT_FAILED, payload)
events.export_failed_info_sent_event(export_file=export_file, user=export_file.user)
diff --git a/saleor/csv/tests/test_notifications.py b/saleor/csv/tests/test_notifications.py
index 8d649a8fcc..94fe53727c 100644
--- a/saleor/csv/tests/test_notifications.py
+++ b/saleor/csv/tests/test_notifications.py
@@ -26,8 +26,11 @@ def test_send_export_download_link_notification(
notifications.send_export_download_link_notification(user_export_file)
# then
- expected_payload = get_default_export_payload(user_export_file)
- expected_payload["csv_link"] = build_absolute_uri(user_export_file.content_file.url)
+ expected_payload = {
+ "export": get_default_export_payload(user_export_file),
+ "csv_link": build_absolute_uri(user_export_file.content_file.url),
+ "recipient_email": user_export_file.user.email,
+ }
mocked_notify.assert_called_once_with(
AdminNotifyEvent.CSV_PRODUCT_EXPORT_SUCCESS, expected_payload
@@ -56,7 +59,10 @@ def test_send_export_failed_info(
notifications.send_export_failed_info(user_export_file)
# then
- expected_payload = get_default_export_payload(user_export_file)
+ expected_payload = {
+ "export": get_default_export_payload(user_export_file),
+ "recipient_email": user_export_file.user.email,
+ }
mocked_notify.assert_called_once_with(
AdminNotifyEvent.CSV_EXPORT_FAILED, expected_payload
diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.py
index 399b1abeb7..9359c50802 100644
--- a/saleor/graphql/account/tests/test_account.py
+++ b/saleor/graphql/account/tests/test_account.py
@@ -728,9 +728,12 @@ def test_customer_register(mocked_notify, mocked_generator, api_client):
content = get_graphql_content(response)
data = content["data"][mutation_name]
- expected_payload = get_default_user_payload(new_user)
- expected_payload["token"] = "token"
- expected_payload["redirect_url"] = "http://localhost:3000"
+ expected_payload = {
+ "user": get_default_user_payload(new_user),
+ "token": "token",
+ "redirect_url": "http://localhost:3000",
+ "recipient_email": new_user.email,
+ }
assert not data["accountErrors"]
mocked_notify.assert_called_once_with(
@@ -864,9 +867,12 @@ def test_customer_create(
assert data["user"]["isActive"]
new_user = User.objects.get(email=email)
- expected_payload = get_default_user_payload(new_user)
- expected_payload["token"] = "token"
- expected_payload["redirect_url"] = "https://www.example.com"
+ expected_payload = {
+ "user": get_default_user_payload(new_user),
+ "token": "token",
+ "redirect_url": "https://www.example.com",
+ "recipient_email": new_user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_SET_CUSTOMER_PASSWORD, payload=expected_payload
)
@@ -895,9 +901,12 @@ def test_customer_create_send_password_with_url(
new_customer = User.objects.get(email=email)
assert new_customer
- expected_payload = get_default_user_payload(new_customer)
- expected_payload["redirect_url"] = "https://www.example.com"
- expected_payload["token"] = "token"
+ expected_payload = {
+ "user": get_default_user_payload(new_customer),
+ "redirect_url": "https://www.example.com",
+ "token": "token",
+ "recipient_email": new_customer.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_SET_CUSTOMER_PASSWORD, payload=expected_payload
)
@@ -1238,9 +1247,12 @@ def test_account_request_deletion(mocked_notify, mocked_token, user_api_client):
content = get_graphql_content(response)
data = content["data"]["accountRequestDeletion"]
assert not data["errors"]
- expected_payload = get_default_user_payload(user)
- expected_payload["redirect_url"] = "https://www.example.com"
- expected_payload["token"] = "token"
+ expected_payload = {
+ "user": get_default_user_payload(user),
+ "redirect_url": "https://www.example.com",
+ "token": "token",
+ "recipient_email": user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_DELETE, payload=expected_payload
@@ -1260,9 +1272,12 @@ def test_account_request_deletion_token_validation(mocked_notify, user_api_clien
data = content["data"]["accountRequestDeletion"]
assert not data["errors"]
- expected_payload = get_default_user_payload(user)
- expected_payload["redirect_url"] = "https://www.example.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(user),
+ "redirect_url": "https://www.example.com",
+ "token": token,
+ "recipient_email": user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_DELETE, payload=expected_payload
@@ -1311,9 +1326,12 @@ def test_account_request_deletion_all_storefront_hosts_allowed(
data = content["data"]["accountRequestDeletion"]
assert not data["errors"]
- expected_payload = get_default_user_payload(user)
- expected_payload["redirect_url"] = "https://www.test.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(user),
+ "redirect_url": "https://www.test.com",
+ "token": token,
+ "recipient_email": user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_DELETE, payload=expected_payload
@@ -1333,9 +1351,12 @@ def test_account_request_deletion_subdomain(mocked_notify, user_api_client, sett
content = get_graphql_content(response)
data = content["data"]["accountRequestDeletion"]
assert not data["errors"]
- expected_payload = get_default_user_payload(user)
- expected_payload["redirect_url"] = "https://sub.example.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(user),
+ "redirect_url": "https://sub.example.com",
+ "token": token,
+ "recipient_email": user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_DELETE, payload=expected_payload
@@ -1560,9 +1581,12 @@ def test_staff_create(
assert {perm["code"].lower() for perm in groups[0]["permissions"]} == expected_perms
token = default_token_generator.make_token(staff_user)
- expected_payload = get_default_user_payload(staff_user)
- expected_payload["redirect_url"] = "https://www.example.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(staff_user),
+ "redirect_url": "https://www.example.com",
+ "token": token,
+ "recipient_email": staff_user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_SET_STAFF_PASSWORD, payload=expected_payload
@@ -1682,9 +1706,12 @@ def test_staff_create_out_of_scope_group(
assert group in groups
token = default_token_generator.make_token(staff_user)
- expected_payload = get_default_user_payload(staff_user)
- expected_payload["redirect_url"] = "https://www.example.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(staff_user),
+ "redirect_url": "https://www.example.com",
+ "token": token,
+ "recipient_email": staff_user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_SET_STAFF_PASSWORD, payload=expected_payload
@@ -1710,9 +1737,12 @@ def test_staff_create_send_password_with_url(
assert staff_user.is_staff
token = default_token_generator.make_token(staff_user)
- expected_payload = get_default_user_payload(staff_user)
- expected_payload["redirect_url"] = "https://www.example.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(staff_user),
+ "redirect_url": "https://www.example.com",
+ "token": token,
+ "recipient_email": staff_user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_SET_STAFF_PASSWORD, payload=expected_payload
@@ -3001,9 +3031,12 @@ def test_account_reset_password(mocked_notify, user_api_client, customer_user):
data = content["data"]["requestPasswordReset"]
assert not data["errors"]
token = default_token_generator.make_token(customer_user)
- expected_payload = get_default_user_payload(customer_user)
- expected_payload["redirect_url"] = "https://www.example.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(customer_user),
+ "redirect_url": "https://www.example.com",
+ "token": token,
+ "recipient_email": customer_user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_PASSWORD_RESET, payload=expected_payload
@@ -3075,9 +3108,12 @@ def test_request_password_reset_email_for_staff(mocked_notify, staff_api_client)
data = content["data"]["requestPasswordReset"]
assert not data["errors"]
token = default_token_generator.make_token(staff_api_client.user)
- expected_payload = get_default_user_payload(staff_api_client.user)
- expected_payload["redirect_url"] = "https://www.example.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(staff_api_client.user),
+ "redirect_url": "https://www.example.com",
+ "token": token,
+ "recipient_email": staff_api_client.user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_PASSWORD_RESET, payload=expected_payload
@@ -3123,9 +3159,12 @@ def test_account_reset_password_all_storefront_hosts_allowed(
assert not data["errors"]
token = default_token_generator.make_token(customer_user)
- expected_payload = get_default_user_payload(customer_user)
- expected_payload["redirect_url"] = "https://www.test.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(customer_user),
+ "redirect_url": "https://www.test.com",
+ "token": token,
+ "recipient_email": customer_user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_PASSWORD_RESET, payload=expected_payload
@@ -3145,9 +3184,12 @@ def test_account_reset_password_subdomain(
assert not data["errors"]
token = default_token_generator.make_token(customer_user)
- expected_payload = get_default_user_payload(customer_user)
- expected_payload["redirect_url"] = "https://sub.example.com"
- expected_payload["token"] = token
+ expected_payload = {
+ "user": get_default_user_payload(customer_user),
+ "redirect_url": "https://sub.example.com",
+ "token": token,
+ "recipient_email": customer_user.email,
+ }
mocked_notify.assert_called_once_with(
NotifyEventType.ACCOUNT_PASSWORD_RESET, payload=expected_payload
diff --git a/saleor/graphql/invoice/tests/test_send_invoice_notification.py b/saleor/graphql/invoice/tests/test_send_invoice_notification.py
index a7ddca1aff..3f1bbfe9c2 100644
--- a/saleor/graphql/invoice/tests/test_send_invoice_notification.py
+++ b/saleor/graphql/invoice/tests/test_send_invoice_notification.py
@@ -37,7 +37,10 @@ def test_invoice_send_notification(
INVOICE_SEND_EMAIL_MUTATION, variables, permissions=[permission_manage_orders]
)
content = get_graphql_content(response)
- expected_payload = get_invoice_payload(invoice)
+ expected_payload = {
+ "invoice": get_invoice_payload(invoice),
+ "recipient_email": invoice.order.get_customer_email(),
+ }
mock_notify.assert_called_once_with(NotifyEventType.INVOICE_READY, expected_payload)
assert not content["data"]["invoiceSendNotification"]["invoiceErrors"]
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.py
index edd1dbc337..5c26e5f623 100644
--- a/saleor/graphql/order/mutations/fulfillments.py
+++ b/saleor/graphql/order/mutations/fulfillments.py
@@ -12,8 +12,8 @@ from ....order.actions import (
create_fulfillments,
fulfillment_tracking_updated,
)
-from ....order.emails import send_fulfillment_update
from ....order.error_codes import OrderErrorCode
+from ....order.notifications import send_fulfillment_update
from ...core.mutations import BaseMutation
from ...core.types.common import OrderError
from ...core.utils import from_global_id_strict_type, get_duplicated_values
@@ -299,7 +299,7 @@ class FulfillmentUpdateTracking(BaseMutation):
input_data = data.get("input", {})
notify_customer = input_data.get("notify_customer")
if notify_customer:
- send_fulfillment_update.delay(order.pk, fulfillment.pk)
+ send_fulfillment_update(order, fulfillment, info.context.plugins)
return FulfillmentUpdateTracking(fulfillment=fulfillment, order=order)
diff --git a/saleor/graphql/order/tests/test_fulfillment.py b/saleor/graphql/order/tests/test_fulfillment.py
index baf96914d4..38d3893913 100644
--- a/saleor/graphql/order/tests/test_fulfillment.py
+++ b/saleor/graphql/order/tests/test_fulfillment.py
@@ -1,4 +1,4 @@
-from unittest.mock import patch
+from unittest.mock import ANY, patch
import graphene
import pytest
@@ -506,7 +506,7 @@ def test_order_fulfill_warehouse_duplicated_order_line_id(
mock_create_fulfillments.assert_not_called()
-@patch("saleor.order.emails.send_fulfillment_update.delay")
+@patch("saleor.plugins.manager.PluginsManager.notify")
def test_fulfillment_update_tracking(
send_fulfillment_update_mock,
staff_api_client,
@@ -548,7 +548,7 @@ FULFILLMENT_UPDATE_TRACKING_WITH_SEND_NOTIFICATION_QUERY = """
"""
-@patch("saleor.order.emails.send_fulfillment_update.delay")
+@patch("saleor.graphql.order.mutations.fulfillments.send_fulfillment_update")
def test_fulfillment_update_tracking_send_notification_true(
send_fulfillment_update_mock,
staff_api_client,
@@ -567,11 +567,11 @@ def test_fulfillment_update_tracking_send_notification_true(
data = content["data"]["orderFulfillmentUpdateTracking"]["fulfillment"]
assert data["trackingNumber"] == tracking
send_fulfillment_update_mock.assert_called_once_with(
- fulfillment.order.pk, fulfillment.pk
+ fulfillment.order, fulfillment, ANY
)
-@patch("saleor.order.emails.send_fulfillment_update.delay")
+@patch("saleor.order.notifications.send_fulfillment_update")
def test_fulfillment_update_tracking_send_notification_false(
send_fulfillment_update_mock,
staff_api_client,
diff --git a/saleor/invoice/notifications.py b/saleor/invoice/notifications.py
index 2b2792d0f4..73e246644f 100644
--- a/saleor/invoice/notifications.py
+++ b/saleor/invoice/notifications.py
@@ -10,13 +10,15 @@ def get_invoice_payload(invoice):
"id": invoice.id,
"number": invoice.number,
"download_url": invoice.url,
- "recipient": invoice.order.get_customer_email(),
}
def send_invoice(invoice: "Invoice", staff_user: "User", manager: "PluginsManager"):
"""Send an invoice to user of related order with URL to download it."""
- invoice_payload = get_invoice_payload(invoice)
- manager.notify(NotifyEventType.INVOICE_READY, invoice_payload)
+ payload = {
+ "invoice": get_invoice_payload(invoice),
+ "recipient_email": invoice.order.get_customer_email(), # type: ignore
+ }
+ manager.notify(NotifyEventType.INVOICE_READY, payload)
manager.invoice_sent(invoice, invoice.order.get_customer_email()) # type: ignore
events.invoice_sent_event(user=staff_user, invoice=invoice)
diff --git a/saleor/invoice/tests/test_notifications.py b/saleor/invoice/tests/test_notifications.py
index 0a6dedf717..141634525f 100644
--- a/saleor/invoice/tests/test_notifications.py
+++ b/saleor/invoice/tests/test_notifications.py
@@ -10,4 +10,3 @@ def test_collect_invoice_data_for_email(order):
assert payload["id"] == invoice.id
assert payload["number"] == number
assert payload["download_url"] == url
- assert payload["recipient"] == order.user.email
diff --git a/saleor/order/actions.py b/saleor/order/actions.py
index ee56ab47eb..6ed24efbf5 100644
--- a/saleor/order/actions.py
+++ b/saleor/order/actions.py
@@ -9,14 +9,14 @@ from ..core.exceptions import InsufficientStock
from ..payment import ChargeStatus, CustomPaymentChoices, PaymentError
from ..plugins.manager import get_plugins_manager
from ..warehouse.management import deallocate_stock_for_order, decrease_stock
-from . import FulfillmentStatus, OrderStatus, emails, events, utils
-from .emails import (
+from . import FulfillmentStatus, OrderStatus, events, utils
+from .models import Fulfillment, FulfillmentLine
+from .notifications import (
send_fulfillment_confirmation_to_customer,
send_order_canceled_confirmation,
send_order_refunded_confirmation,
send_payment_confirmation,
)
-from .models import Fulfillment, FulfillmentLine
from .utils import (
order_line_needs_automatic_fulfillment,
recalculate_order,
@@ -52,12 +52,12 @@ def order_created(order: "Order", user: "User", from_draft: bool = False):
def handle_fully_paid_order(order: "Order", user: Optional["User"] = None):
events.order_fully_paid_event(order=order, user=user)
-
+ manager = get_plugins_manager()
if order.get_customer_email():
events.email_sent_event(
order=order, user=user, email_type=events.OrderEventsEmails.PAYMENT
)
- send_payment_confirmation.delay(order.pk)
+ send_payment_confirmation(order, manager)
if utils.order_needs_automatic_fulfillment(order):
automatically_fulfill_digital_lines(order)
@@ -66,7 +66,6 @@ def handle_fully_paid_order(order: "Order", user: Optional["User"] = None):
except Exception:
# Analytics failing should not abort the checkout flow
logger.exception("Recording order in analytics failed")
- manager = get_plugins_manager()
manager.order_fully_paid(order)
manager.order_updated(order)
@@ -88,7 +87,7 @@ def cancel_order(order: "Order", user: Optional["User"]):
manager.order_cancelled(order)
manager.order_updated(order)
- send_order_canceled_confirmation(order, user)
+ send_order_canceled_confirmation(order, user, manager)
def order_refunded(
@@ -97,9 +96,10 @@ def order_refunded(
events.payment_refunded_event(
order=order, user=user, amount=amount, payment=payment
)
- get_plugins_manager().order_updated(order)
+ manager = get_plugins_manager()
+ manager.order_updated(order)
- send_order_refunded_confirmation(order, user, amount, payment.currency)
+ send_order_refunded_confirmation(order, user, amount, payment.currency, manager)
def order_voided(order: "Order", user: "User", payment: "Payment"):
@@ -129,7 +129,7 @@ def order_fulfilled(
if notify_customer:
for fulfillment in fulfillments:
- send_fulfillment_confirmation_to_customer(order, fulfillment, user)
+ send_fulfillment_confirmation_to_customer(order, fulfillment, user, manager)
def order_shipping_updated(order: "Order"):
@@ -263,8 +263,10 @@ def automatically_fulfill_digital_lines(order: "Order"):
fulfill_order_line(
order_line=line, quantity=quantity, warehouse_pk=warehouse_pk
)
- emails.send_fulfillment_confirmation_to_customer(
- order, fulfillment, user=order.user
+
+ manager = get_plugins_manager()
+ send_fulfillment_confirmation_to_customer(
+ order, fulfillment, user=order.user, manager=manager
)
update_order_status(order)
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
deleted file mode 100644
index dd30ff64a7..0000000000
--- a/saleor/order/emails.py
+++ /dev/null
@@ -1,182 +0,0 @@
-from typing import TYPE_CHECKING, Optional
-from urllib.parse import urlencode
-
-from templated_email import send_templated_mail
-
-from ..account.models import StaffNotificationRecipient
-from ..celeryconf import app
-from ..core.emails import get_email_context
-from ..core.utils.url import prepare_url
-from ..seo.schema.email import get_order_confirmation_markup
-from . import events
-from .models import Fulfillment, Order
-
-if TYPE_CHECKING:
- from decimal import Decimal
-
- from ..account.models import User # noqa: F401
-
-CONFIRM_ORDER_TEMPLATE = "order/confirm_order"
-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(
- order_pk: int, template: str, redirect_url: str
-) -> dict:
- data = collect_data_for_email(order_pk, template, redirect_url)
- staff_notifications = StaffNotificationRecipient.objects.filter(
- active=True, user__is_active=True, user__is_staff=True
- )
- recipient_emails = [
- notification.get_email() for notification in staff_notifications
- ]
- data["recipient_list"] = recipient_emails
- return data
-
-
-def collect_data_for_email(
- order_pk: int, template: str, redirect_url: str = ""
-) -> dict:
- """Collect the required data for sending emails."""
- order = Order.objects.prefetch_related("lines__variant__product__images").get(
- pk=order_pk
- )
- recipient_email = order.get_customer_email()
- send_kwargs, email_context = get_email_context()
-
- email_context["order_details_url"] = (
- prepare_order_details_url(order, redirect_url) if redirect_url else ""
- )
- email_context["order"] = order
-
- # Order confirmation template requires additional information
- if template in [CONFIRM_ORDER_TEMPLATE, STAFF_CONFIRM_ORDER_TEMPLATE]:
- email_markup = get_order_confirmation_markup(order)
- email_context["schema_markup"] = email_markup
-
- return {
- "recipient_list": [recipient_email],
- "template_name": template,
- "context": email_context,
- **send_kwargs,
- }
-
-
-def prepare_order_details_url(order: Order, redirect_url: str) -> str:
- params = urlencode({"token": order.token})
- return prepare_url(params, redirect_url)
-
-
-def collect_data_for_fulfillment_email(order_pk, template, fulfillment_pk):
- fulfillment = Fulfillment.objects.get(pk=fulfillment_pk)
- email_data = collect_data_for_email(order_pk, template)
- lines = fulfillment.lines.all()
- physical_lines = [line for line in lines if not line.order_line.is_digital]
- digital_lines = [line for line in lines if line.order_line.is_digital]
- context = email_data["context"]
- context.update(
- {
- "fulfillment": fulfillment,
- "physical_lines": physical_lines,
- "digital_lines": digital_lines,
- }
- )
- return email_data
-
-
-def send_order_confirmation(order_pk, redirect_url, user_pk=None):
- """Send order confirmation email."""
- email_data = collect_data_for_email(order_pk, CONFIRM_ORDER_TEMPLATE, redirect_url)
- send_templated_mail(**email_data)
- events.email_sent_event(
- order=email_data["context"]["order"],
- user=None,
- user_pk=user_pk,
- email_type=events.OrderEventsEmails.ORDER_CONFIRMATION,
- )
-
-
-def send_staff_order_confirmation(order_pk, redirect_url):
- """Send order confirmation email."""
- staff_email_data = collect_staff_order_notification_data(
- order_pk, STAFF_CONFIRM_ORDER_TEMPLATE, redirect_url
- )
- if staff_email_data["recipient_list"]:
- send_templated_mail(**staff_email_data)
-
-
-def send_fulfillment_confirmation(order_pk, fulfillment_pk):
- email_data = collect_data_for_fulfillment_email(
- order_pk, CONFIRM_FULFILLMENT_TEMPLATE, fulfillment_pk
- )
- send_templated_mail(**email_data)
-
-
-def send_fulfillment_confirmation_to_customer(order, fulfillment, user):
- send_fulfillment_confirmation.delay(order.pk, fulfillment.pk)
-
- events.email_sent_event(
- order=order, user=user, email_type=events.OrderEventsEmails.FULFILLMENT
- )
-
- # If digital lines were sent in the fulfillment email,
- # trigger the event
- if any((line for line in order if line.variant.is_digital())):
- events.email_sent_event(
- order=order, user=user, email_type=events.OrderEventsEmails.DIGITAL_LINKS
- )
-
-
-def send_fulfillment_update(order_pk, fulfillment_pk):
- email_data = collect_data_for_fulfillment_email(
- order_pk, UPDATE_FULFILLMENT_TEMPLATE, fulfillment_pk
- )
- send_templated_mail(**email_data)
-
-
-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_canceled_confirmation(order: "Order", user: Optional["User"]):
- send_order_canceled.delay(order.pk)
- events.email_sent_event(
- order=order, user=user, email_type=events.OrderEventsEmails.ORDER_CANCEL
- )
-
-
-def send_order_canceled(order_pk: int):
- """Send order cancel email."""
- email_data = collect_data_for_email(order_pk, ORDER_CANCEl_TEMPLATE)
- send_templated_mail(**email_data)
-
-
-def send_order_refunded_confirmation(
- order: "Order", user: Optional["User"], amount: "Decimal", currency: str
-):
- send_order_refunded.delay(order.pk, amount, currency)
- events.email_sent_event(
- order=order, user=user, email_type=events.OrderEventsEmails.ORDER_REFUND
- )
-
-
-def send_order_refunded(order_pk: int, amount: "Decimal", currency: str):
- """Send order refund email."""
- email_data = collect_data_for_email(order_pk, ORDER_REFUND_TEMPLATE)
- context = email_data["context"]
- context.update({"amount": amount, "currency": currency})
- send_templated_mail(**email_data)
diff --git a/saleor/order/notifications.py b/saleor/order/notifications.py
new file mode 100644
index 0000000000..1c1cb17527
--- /dev/null
+++ b/saleor/order/notifications.py
@@ -0,0 +1,250 @@
+from typing import TYPE_CHECKING, Iterable, Optional
+from urllib.parse import urlencode
+
+from django.forms import model_to_dict
+
+from ..account.models import StaffNotificationRecipient
+from ..core.notify_events import NotifyEventType
+from ..core.utils.url import prepare_url
+from ..product.models import DigitalContentUrl
+from . import events
+from .models import FulfillmentLine, Order, OrderLine
+
+if TYPE_CHECKING:
+ from decimal import Decimal
+
+ from ..account.models import User # noqa: F401
+
+
+def get_order_line_payload(line: "OrderLine"):
+ unit_tax_amount = (line.unit_price_gross_amount - line.unit_price_net_amount,)
+ total_gross = line.unit_price_gross * line.quantity
+ total_net = line.unit_price_net * line.quantity
+ total_tax = total_gross - total_net
+ digital_url = ""
+ if line.is_digital:
+ content = DigitalContentUrl.objects.filter(line=line).first()
+ digital_url = content.get_absolute_url() if content else None # type: ignore
+ return {
+ "id": line.id,
+ "product_name": line.translated_product_name or line.product_name,
+ "variant_name": line.translated_variant_name or line.variant_name,
+ "product_sku": line.product_sku,
+ "quantity": line.quantity,
+ "quantity_fulfilled": line.quantity_fulfilled,
+ "currency": line.currency,
+ "unit_price_net_amount": line.unit_price_net_amount,
+ "unit_price_gross_amount": line.unit_price_gross_amount,
+ "unit_tax_amount": unit_tax_amount,
+ "total_gross_amount": total_gross.amount,
+ "total_net_amount": total_net.amount,
+ "total_tax_amount": total_tax.amount,
+ "tax_rate": line.tax_rate,
+ "is_shipping_required": line.is_shipping_required,
+ "is_digital": line.is_digital,
+ "digital_url": digital_url,
+ }
+
+
+def get_lines_payload(order_lines: Iterable["OrderLine"]):
+ payload = []
+ for line in order_lines:
+ payload.append(get_order_line_payload(line))
+ return payload
+
+
+ADDRESS_MODEL_FIELDS = [
+ "first_name",
+ "last_name",
+ "company_name",
+ "street_address_1",
+ "street_address_2",
+ "city",
+ "city_area",
+ "postal_code",
+ "country",
+ "country_area",
+ "phone",
+]
+
+
+def get_address_payload(address):
+ if not address:
+ return None
+ address = model_to_dict(address, fields=ADDRESS_MODEL_FIELDS)
+ address["country"] = str(address["country"])
+ address["phone"] = str(address["phone"])
+ return address
+
+
+ORDER_MODEL_FIELDS = [
+ "id",
+ "token",
+ "display_gross_prices",
+ "currency",
+ "discount_amount",
+ "total_gross_amount",
+ "total_net_amount",
+ "status",
+ "metadata",
+ "private_metadata",
+]
+
+
+def get_default_order_payload(order: "Order", redirect_url: str = ""):
+ order_details_url = ""
+ if redirect_url:
+ order_details_url = prepare_order_details_url(order, redirect_url)
+ subtotal = order.get_subtotal()
+ tax = order.total_gross_amount - order.total_net_amount
+
+ order_payload = model_to_dict(order, fields=ORDER_MODEL_FIELDS)
+ order_payload.update(
+ {
+ "created": order.created,
+ "shipping_price_net_amount": order.shipping_price_net_amount,
+ "shipping_price_gross_amount": order.shipping_price_gross_amount,
+ "order_details_url": order_details_url,
+ "email": order.get_customer_email(),
+ "subtotal_gross_amount": subtotal.gross.amount,
+ "subtotal_net_amount": subtotal.net.amount,
+ "tax_amount": tax,
+ "discount_name": order.translated_discount_name or order.discount_name,
+ "lines": get_lines_payload(order.lines.all()),
+ "billing_address": get_address_payload(order.billing_address),
+ "shipping_address": get_address_payload(order.shipping_address),
+ "shipping_method_name": order.shipping_method_name,
+ }
+ )
+ return order_payload
+
+
+def get_default_fulfillment_line_payload(line: "FulfillmentLine"):
+ return {
+ "id": line.id,
+ "order_line": get_order_line_payload(line.order_line),
+ "quantity": line.quantity,
+ }
+
+
+def get_default_fulfillment_payload(order, fulfillment):
+ lines = fulfillment.lines.all()
+ physical_lines = [line for line in lines if not line.order_line.is_digital]
+
+ digital_lines = [line for line in lines if line.order_line.is_digital]
+ payload = {
+ "order": get_default_order_payload(order),
+ "fulfillment": {
+ "tracking_number": fulfillment.tracking_number,
+ "is_tracking_number_url": fulfillment.is_tracking_number_url,
+ },
+ "physical_lines": [
+ get_default_fulfillment_line_payload(line) for line in physical_lines
+ ],
+ "digital_lines": [
+ get_default_fulfillment_line_payload(line) for line in digital_lines
+ ],
+ "recipient_email": order.get_customer_email(),
+ }
+ return payload
+
+
+def prepare_order_details_url(order: Order, redirect_url: str) -> str:
+ params = urlencode({"token": order.token})
+ return prepare_url(params, redirect_url)
+
+
+def send_order_confirmation(order, redirect_url, user, manager):
+ """Send notification with order confirmation."""
+ payload = {
+ "order": get_default_order_payload(order, redirect_url),
+ "recipient_email": order.get_customer_email(),
+ }
+ manager.notify(NotifyEventType.ORDER_CONFIRMATION, payload)
+ events.email_sent_event(
+ order=order,
+ user=None,
+ user_pk=user.pk if user else None,
+ email_type=events.OrderEventsEmails.ORDER_CONFIRMATION,
+ )
+
+
+def send_staff_order_confirmation(order, redirect_url, manager):
+ """Send staff notification with order confirmation."""
+ staff_notifications = StaffNotificationRecipient.objects.filter(
+ active=True, user__is_active=True, user__is_staff=True
+ )
+ recipient_emails = [
+ notification.get_email() for notification in staff_notifications
+ ]
+ if recipient_emails:
+ payload = {
+ "order": get_default_order_payload(order, redirect_url),
+ "recipient_list": recipient_emails,
+ }
+ manager.notify(NotifyEventType.STAFF_ORDER_CONFIRMATION, payload=payload)
+
+
+def send_fulfillment_confirmation_to_customer(order, fulfillment, user, manager):
+ payload = get_default_fulfillment_payload(order, fulfillment)
+ manager.notify(NotifyEventType.ORDER_FULFILLMENT_CONFIRMATION, payload=payload)
+
+ events.email_sent_event(
+ order=order, user=user, email_type=events.OrderEventsEmails.FULFILLMENT
+ )
+
+ # If digital lines were sent in the fulfillment email,
+ # trigger the event
+ if any((line for line in order if line.variant.is_digital())):
+ events.email_sent_event(
+ order=order, user=user, email_type=events.OrderEventsEmails.DIGITAL_LINKS
+ )
+
+
+def send_fulfillment_update(order, fulfillment, manager):
+ payload = get_default_fulfillment_payload(order, fulfillment)
+ manager.notify(NotifyEventType.ORDER_FULFILLMENT_UPDATE, payload)
+
+
+def send_payment_confirmation(order, manager):
+ """Send notification with the payment confirmation."""
+ payment = order.get_last_payment()
+ payload = {
+ "order": get_default_order_payload(order),
+ "recipient_email": order.get_customer_email(),
+ "payment": {
+ "created": payment.created,
+ "modified": payment.modified,
+ "charge_status": payment.charge_status,
+ "total": payment.total,
+ "captured_amount": payment.captured_amount,
+ "currency": payment.currency,
+ },
+ }
+ manager.notify(NotifyEventType.ORDER_PAYMENT_CONFIRMATION, payload)
+
+
+def send_order_canceled_confirmation(order: "Order", user: Optional["User"], manager):
+ payload = {
+ "order": get_default_order_payload(order),
+ "recipient_email": order.get_customer_email(),
+ }
+ manager.notify(NotifyEventType.ORDER_CANCELED, payload)
+ events.email_sent_event(
+ order=order, user=user, email_type=events.OrderEventsEmails.ORDER_CANCEL
+ )
+
+
+def send_order_refunded_confirmation(
+ order: "Order", user: Optional["User"], amount: "Decimal", currency: str, manager
+):
+ payload = {
+ "order": get_default_order_payload(order),
+ "recipient_email": order.get_customer_email(),
+ "amount": amount,
+ "currency": currency,
+ }
+ manager.notify(NotifyEventType.ORDER_REFUND_CONFIRMATION, payload)
+ events.email_sent_event(
+ order=order, user=user, email_type=events.OrderEventsEmails.ORDER_REFUND
+ )
diff --git a/saleor/order/tests/test_emails.py b/saleor/order/tests/test_emails.py
deleted file mode 100644
index 1c28eda766..0000000000
--- a/saleor/order/tests/test_emails.py
+++ /dev/null
@@ -1,345 +0,0 @@
-from decimal import Decimal
-from unittest import mock
-
-import pytest
-from templated_email import get_connection
-
-from ...order import OrderEvents, emails as emails
-from ..utils import add_variant_to_draft_order
-
-
-def test_collect_data_for_order_confirmation_email(order):
- """Order confirmation email requires extra data, which should be present
- in email's context.
- """
- template = emails.CONFIRM_ORDER_TEMPLATE
- email_data = emails.collect_data_for_email(order.pk, template)
- email_context = email_data["context"]
- assert email_context["order"] == order
- assert "schema_markup" in email_context
-
-
-def test_collect_data_for_fulfillment_email(fulfilled_order):
- template = emails.CONFIRM_FULFILLMENT_TEMPLATE
- fulfillment = fulfilled_order.fulfillments.first()
- fulfillment_data = emails.collect_data_for_fulfillment_email(
- fulfilled_order.pk, template, fulfillment.pk
- )
- email_context = fulfillment_data["context"]
- assert email_context["fulfillment"] == fulfillment
- email_data = emails.collect_data_for_email(fulfilled_order.pk, template)
- assert all([key in email_context for key, item in email_data["context"].items()])
-
-
-def test_collect_data_for_email(order):
- template = emails.CONFIRM_PAYMENT_TEMPLATE
- email_data = emails.collect_data_for_email(order.pk, template)
- email_context = email_data["context"]
- # This properties should be present only for order confirmation email
- assert "schema_markup" not in email_context
-
-
[email protected]("saleor.order.emails.send_templated_mail")
-def test_send_email_payment_confirmation(mocked_templated_email, order, site_settings):
- template = emails.CONFIRM_PAYMENT_TEMPLATE
- emails.send_payment_confirmation(order.pk)
- 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_staff_emails_without_notification_recipient(
- mocked_templated_email, order, site_settings
-):
- emails.send_staff_order_confirmation(order.pk, "http://www.example.com/")
- mocked_templated_email.assert_not_called()
-
-
[email protected]("saleor.order.emails.send_templated_mail")
-def test_send_staff_emails(
- mocked_templated_email, order, site_settings, staff_notification_recipient
-):
- redirect_url = "http://www.example.com/"
- emails.send_staff_order_confirmation(order.pk, redirect_url)
- email_data = emails.collect_staff_order_notification_data(
- order.pk, emails.STAFF_CONFIRM_ORDER_TEMPLATE, redirect_url
- )
-
- recipients = [staff_notification_recipient.get_email()]
-
- expected_call_kwargs = {
- "context": email_data["context"],
- "from_email": site_settings.default_from_email,
- "template_name": emails.STAFF_CONFIRM_ORDER_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_confirmation(mocked_templated_email, order, site_settings):
- template = emails.CONFIRM_ORDER_TEMPLATE
- redirect_url = "https://www.example.com"
- emails.send_order_confirmation(order.pk, redirect_url)
- email_data = emails.collect_data_for_email(order.pk, template, redirect_url)
-
- 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_confirmation_emails_without_addresses_for_payment(
- mocked_templated_email, order, site_settings, digital_content
-):
-
- assert not order.lines.count()
-
- template = emails.CONFIRM_PAYMENT_TEMPLATE
- add_variant_to_draft_order(order, digital_content.product_variant, quantity=1)
- order.shipping_address = None
- order.shipping_method = None
- order.billing_address = None
- order.save(update_fields=["shipping_address", "shipping_method", "billing_address"])
-
- emails.send_payment_confirmation(order.pk)
- 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_confirmation_emails_without_addresses_for_order(
- mocked_templated_email, order, site_settings, digital_content
-):
-
- assert not order.lines.count()
-
- template = emails.CONFIRM_ORDER_TEMPLATE
- add_variant_to_draft_order(order, digital_content.product_variant, quantity=1)
- order.shipping_address = None
- order.shipping_method = None
- order.billing_address = None
- order.save(update_fields=["shipping_address", "shipping_method", "billing_address"])
-
- redirect_url = "https://www.example.com"
- emails.send_order_confirmation(order.pk, redirect_url)
- email_data = emails.collect_data_for_email(order.pk, template, redirect_url)
-
- 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)
-
-
- "send_email,template",
- [
- (
- emails.send_fulfillment_confirmation,
- emails.CONFIRM_FULFILLMENT_TEMPLATE,
- ), # noqa
- (emails.send_fulfillment_update, emails.UPDATE_FULFILLMENT_TEMPLATE),
- ],
-)
[email protected]("saleor.order.emails.send_templated_mail")
-def test_send_fulfillment_emails(
- mocked_templated_email, template, send_email, fulfilled_order, site_settings
-):
- fulfillment = fulfilled_order.fulfillments.first()
- send_email(order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk)
- email_data = emails.collect_data_for_fulfillment_email(
- fulfilled_order.pk, template, fulfillment.pk
- )
-
- recipients = [fulfilled_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)
-
-
- "send_email,template",
- [
- (
- emails.send_fulfillment_confirmation,
- emails.CONFIRM_FULFILLMENT_TEMPLATE,
- ), # noqa
- (emails.send_fulfillment_update, emails.UPDATE_FULFILLMENT_TEMPLATE),
- ],
-)
[email protected]("saleor.order.emails.send_templated_mail")
-def test_send_fulfillment_emails_with_tracking_number_as_url(
- mocked_templated_email, template, send_email, fulfilled_order, site_settings
-):
- fulfillment = fulfilled_order.fulfillments.first()
- fulfillment.tracking_number = "https://www.example.com"
- fulfillment.save()
- assert fulfillment.is_tracking_number_url
- send_email(order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk)
- email_data = emails.collect_data_for_fulfillment_email(
- fulfilled_order.pk, template, fulfillment.pk
- )
-
- recipients = [fulfilled_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_canceled(mocked_templated_email, order, site_settings):
- # given
- template = emails.ORDER_CANCEl_TEMPLATE
-
- # when
- emails.send_order_canceled(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_refunded(mocked_templated_email, order, site_settings):
- # given
- template = emails.ORDER_REFUND_TEMPLATE
- amount = order.total.gross.amount
-
- # when
- emails.send_order_refunded(order.pk, amount, order.currency)
-
- # then
- email_data = emails.collect_data_for_email(order.pk, template)
- email_data["context"].update({"amount": amount, "currency": order.currency})
- 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_order_refunded.delay")
-def test_send_order_refunded_confirmation(send_order_refunded_mock, order):
- # when
- emails.send_order_refunded_confirmation(order, order.user, Decimal(5), "USD")
-
- # then
- send_order_refunded_mock.assert_called_once_with(order.pk, Decimal(5), "USD")
-
- order_event = order.events.last()
- assert order_event.type == OrderEvents.EMAIL_SENT
-
-
[email protected]("saleor.order.emails.send_order_canceled.delay")
-def test_send_order_canceled_confirmation(send_order_canceled_mock, order):
- # when
- emails.send_order_canceled_confirmation(order, order.user)
-
- # then
- send_order_canceled_mock.assert_called_once_with(order.pk)
-
- order_event = order.events.last()
- assert order_event.type == OrderEvents.EMAIL_SENT
diff --git a/saleor/order/tests/test_fulfullments_actions.py b/saleor/order/tests/test_fulfullments_actions.py
index 68d267ce9a..110a5630c8 100644
--- a/saleor/order/tests/test_fulfullments_actions.py
+++ b/saleor/order/tests/test_fulfullments_actions.py
@@ -8,9 +8,14 @@ from ..actions import create_fulfillments
from ..models import FulfillmentLine, OrderStatus
+@patch("saleor.order.actions.get_plugins_manager")
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
def test_create_fulfillments(
- mock_email_fulfillment, staff_user, order_with_lines, warehouse,
+ mock_email_fulfillment,
+ mock_get_plugins_manager,
+ staff_user,
+ order_with_lines,
+ warehouse,
):
order = order_with_lines
order_line1, order_line2 = order.lines.all()
@@ -49,7 +54,7 @@ def test_create_fulfillments(
)
mock_email_fulfillment.assert_called_once_with(
- order, order.fulfillments.get(), staff_user
+ order, order.fulfillments.get(), staff_user, mock_get_plugins_manager()
)
@@ -152,9 +157,14 @@ def test_create_fulfillments_many_warehouses(
)
+@patch("saleor.order.actions.get_plugins_manager")
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
def test_create_fulfillments_with_one_line_empty_quantity(
- mock_email_fulfillment, staff_user, order_with_lines, warehouse,
+ mock_email_fulfillment,
+ mock_get_plugins_manager,
+ staff_user,
+ order_with_lines,
+ warehouse,
):
order = order_with_lines
order_line1, order_line2 = order.lines.all()
@@ -191,13 +201,15 @@ def test_create_fulfillments_with_one_line_empty_quantity(
)
mock_email_fulfillment.assert_called_once_with(
- order, order.fulfillments.get(), staff_user
+ order, order.fulfillments.get(), staff_user, mock_get_plugins_manager()
)
+@patch("saleor.order.actions.get_plugins_manager")
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
def test_create_fulfillments_with_variant_without_inventory_tracking(
mock_email_fulfillment,
+ mock_get_plugins_manager,
staff_user,
order_with_line_without_inventory_tracking,
warehouse,
@@ -231,14 +243,20 @@ def test_create_fulfillments_with_variant_without_inventory_tracking(
assert stock_quantity_before == stock.quantity
mock_email_fulfillment.assert_called_once_with(
- order, order.fulfillments.get(), staff_user
+ order, order.fulfillments.get(), staff_user, mock_get_plugins_manager()
)
+@patch("saleor.order.actions.get_plugins_manager")
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
def test_create_fulfillments_without_allocations(
- mock_email_fulfillment, staff_user, order_with_lines, warehouse,
+ mock_email_fulfillment,
+ mock_get_plugins_manager,
+ staff_user,
+ order_with_lines,
+ warehouse,
):
+
order = order_with_lines
order_line1, order_line2 = order.lines.all()
Allocation.objects.filter(order_line__order=order).delete()
@@ -277,7 +295,7 @@ def test_create_fulfillments_without_allocations(
)
mock_email_fulfillment.assert_called_once_with(
- order, order.fulfillments.get(), staff_user
+ order, order.fulfillments.get(), staff_user, mock_get_plugins_manager()
)
diff --git a/saleor/order/tests/test_notifications.py b/saleor/order/tests/test_notifications.py
new file mode 100644
index 0000000000..b3fd1773a5
--- /dev/null
+++ b/saleor/order/tests/test_notifications.py
@@ -0,0 +1,342 @@
+from unittest import mock
+
+from ...core.notify_events import NotifyEventType
+from ...order import notifications
+from ...plugins.manager import get_plugins_manager
+from ...product.models import DigitalContentUrl
+from ..notifications import (
+ get_address_payload,
+ get_default_fulfillment_line_payload,
+ get_default_fulfillment_payload,
+ get_default_order_payload,
+ get_order_line_payload,
+)
+from ..utils import add_variant_to_draft_order
+
+
+def test_get_order_line_payload(order_line):
+ payload = get_order_line_payload(order_line)
+ unit_tax_amount = (
+ order_line.unit_price_gross_amount - order_line.unit_price_net_amount,
+ )
+ total_gross = order_line.unit_price_gross * order_line.quantity
+ total_net = order_line.unit_price_net * order_line.quantity
+ total_tax = total_gross - total_net
+ assert payload == {
+ "id": order_line.id,
+ "product_name": order_line.translated_product_name or order_line.product_name,
+ "variant_name": order_line.translated_variant_name or order_line.variant_name,
+ "product_sku": order_line.product_sku,
+ "is_shipping_required": order_line.is_shipping_required,
+ "quantity": order_line.quantity,
+ "quantity_fulfilled": order_line.quantity_fulfilled,
+ "currency": order_line.currency,
+ "unit_price_net_amount": order_line.unit_price_net_amount,
+ "unit_price_gross_amount": order_line.unit_price_gross_amount,
+ "unit_tax_amount": unit_tax_amount,
+ "total_gross_amount": total_gross.amount,
+ "total_net_amount": total_net.amount,
+ "total_tax_amount": total_tax.amount,
+ "tax_rate": order_line.tax_rate,
+ "is_digital": order_line.is_digital,
+ "digital_url": "",
+ }
+
+
+def test_get_address_payload(address):
+ payload = get_address_payload(address)
+ assert payload == {
+ "first_name": address.first_name,
+ "last_name": address.last_name,
+ "company_name": address.company_name,
+ "street_address_1": address.street_address_1,
+ "street_address_2": address.street_address_2,
+ "city": address.city,
+ "city_area": address.city_area,
+ "postal_code": address.postal_code,
+ "country": str(address.country),
+ "country_area": address.country_area,
+ "phone": str(address.phone),
+ }
+
+
+def test_get_default_order_payload(order_line):
+ order_line.refresh_from_db()
+ order = order_line.order
+ order_line_payload = get_order_line_payload(order_line)
+ redirect_url = "http://redirect.com/path"
+ payload = get_default_order_payload(order, redirect_url)
+ subtotal = order.get_subtotal()
+ tax = order.total_gross_amount - order.total_net_amount
+ assert payload == {
+ "id": order.id,
+ "token": order.token,
+ "created": order.created,
+ "display_gross_prices": order.display_gross_prices,
+ "currency": order.currency,
+ "discount_amount": order.discount_amount,
+ "total_gross_amount": order.total_gross_amount,
+ "total_net_amount": order.total_net_amount,
+ "shipping_method_name": order.shipping_method_name,
+ "status": order.status,
+ "metadata": order.metadata,
+ "private_metadata": order.private_metadata,
+ "shipping_price_net_amount": order.shipping_price_net_amount,
+ "shipping_price_gross_amount": order.shipping_price_gross_amount,
+ "order_details_url": f"{redirect_url}?token={order.token}",
+ "email": order.get_customer_email(),
+ "subtotal_gross_amount": subtotal.gross.amount,
+ "subtotal_net_amount": subtotal.net.amount,
+ "tax_amount": tax,
+ "discount_name": order.translated_discount_name or order.discount_name,
+ "lines": [order_line_payload],
+ "billing_address": get_address_payload(order.billing_address),
+ "shipping_address": get_address_payload(order.shipping_address),
+ }
+
+
+def test_get_default_fulfillment_payload(
+ fulfillment, digital_content,
+):
+ order = fulfillment.order
+ fulfillment.tracking_number = "http://tracking.url.com/123"
+ fulfillment.save(update_fields=["tracking_number"])
+ line = order.lines.first()
+ line.variant = digital_content.product_variant
+ line.save(update_fields=["variant"])
+ DigitalContentUrl.objects.create(content=digital_content, line=line)
+
+ order_payload = get_default_order_payload(order)
+ payload = get_default_fulfillment_payload(order, fulfillment)
+
+ # make sure that test will not fail because of the list order
+ payload["order"]["lines"] = sorted(payload["order"]["lines"], key=lambda l: l["id"])
+ payload["physical_lines"] = sorted(payload["physical_lines"], key=lambda l: l["id"])
+ order_payload["lines"] = sorted(order_payload["lines"], key=lambda l: l["id"])
+
+ digital_line = fulfillment.lines.get(order_line=line.id)
+ physical_line = fulfillment.lines.exclude(id=digital_line.id).first()
+ assert payload == {
+ "order": order_payload,
+ "fulfillment": {
+ "tracking_number": fulfillment.tracking_number,
+ "is_tracking_number_url": fulfillment.is_tracking_number_url,
+ },
+ "physical_lines": [get_default_fulfillment_line_payload(physical_line)],
+ "digital_lines": [get_default_fulfillment_line_payload(digital_line)],
+ "recipient_email": order.get_customer_email(),
+ }
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_email_payment_confirmation(mocked_notify, site_settings, payment_dummy):
+ manager = get_plugins_manager()
+ order = payment_dummy.order
+ expected_payload = {
+ "order": get_default_order_payload(order),
+ "recipient_email": order.get_customer_email(),
+ "payment": {
+ "created": payment_dummy.created,
+ "modified": payment_dummy.modified,
+ "charge_status": payment_dummy.charge_status,
+ "total": payment_dummy.total,
+ "captured_amount": payment_dummy.captured_amount,
+ "currency": payment_dummy.currency,
+ },
+ }
+ notifications.send_payment_confirmation(order, manager)
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.ORDER_PAYMENT_CONFIRMATION, expected_payload
+ )
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_staff_emails_without_notification_recipient(
+ mocked_notify, order, site_settings
+):
+ manager = get_plugins_manager()
+ notifications.send_staff_order_confirmation(
+ order, "http://www.example.com/", manager
+ )
+ mocked_notify.assert_not_called()
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_staff_emails(
+ mocked_notify, order, site_settings, staff_notification_recipient
+):
+ manager = get_plugins_manager()
+ redirect_url = "http://www.example.com/"
+ notifications.send_staff_order_confirmation(order, redirect_url, manager)
+ expected_payload = {
+ "order": get_default_order_payload(order, redirect_url),
+ "recipient_list": [staff_notification_recipient.get_email()],
+ }
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.STAFF_ORDER_CONFIRMATION, payload=expected_payload
+ )
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_email_order_confirmation(mocked_notify, order, site_settings):
+ manager = get_plugins_manager()
+ redirect_url = "https://www.example.com"
+
+ notifications.send_order_confirmation(order, redirect_url, order.user, manager)
+
+ expected_payload = {
+ "order": get_default_order_payload(order, redirect_url),
+ "recipient_email": order.get_customer_email(),
+ }
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.ORDER_CONFIRMATION, expected_payload
+ )
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_confirmation_emails_without_addresses_for_payment(
+ mocked_notify, site_settings, digital_content, payment_dummy,
+):
+ order = payment_dummy.order
+
+ line = add_variant_to_draft_order(
+ order, digital_content.product_variant, quantity=1
+ )
+ DigitalContentUrl.objects.create(content=digital_content, line=line)
+
+ order.shipping_address = None
+ order.shipping_method = None
+ order.billing_address = None
+ order.save(update_fields=["shipping_address", "shipping_method", "billing_address"])
+
+ manager = get_plugins_manager()
+ notifications.send_payment_confirmation(order, manager)
+
+ expected_payload = {
+ "order": get_default_order_payload(order),
+ "recipient_email": order.get_customer_email(),
+ "payment": {
+ "created": payment_dummy.created,
+ "modified": payment_dummy.modified,
+ "charge_status": payment_dummy.charge_status,
+ "total": payment_dummy.total,
+ "captured_amount": payment_dummy.captured_amount,
+ "currency": payment_dummy.currency,
+ },
+ }
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.ORDER_PAYMENT_CONFIRMATION, expected_payload
+ )
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_confirmation_emails_without_addresses_for_order(
+ mocked_notify, order, site_settings, digital_content
+):
+
+ assert not order.lines.count()
+
+ line = add_variant_to_draft_order(
+ order, digital_content.product_variant, quantity=1
+ )
+ DigitalContentUrl.objects.create(content=digital_content, line=line)
+
+ order.shipping_address = None
+ order.shipping_method = None
+ order.billing_address = None
+ order.save(update_fields=["shipping_address", "shipping_method", "billing_address"])
+
+ redirect_url = "https://www.example.com"
+ manager = get_plugins_manager()
+
+ notifications.send_order_confirmation(order, redirect_url, order.user, manager)
+
+ expected_payload = {
+ "order": get_default_order_payload(order, redirect_url),
+ "recipient_email": order.get_customer_email(),
+ }
+
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.ORDER_CONFIRMATION, expected_payload
+ )
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_fulfillment_confirmation(mocked_notify, fulfilled_order, site_settings):
+ fulfillment = fulfilled_order.fulfillments.first()
+ fulfillment.tracking_number = "https://www.example.com"
+ fulfillment.save()
+ manager = get_plugins_manager()
+
+ notifications.send_fulfillment_confirmation_to_customer(
+ order=fulfilled_order,
+ fulfillment=fulfillment,
+ user=fulfilled_order.user,
+ manager=manager,
+ )
+
+ expected_payload = get_default_fulfillment_payload(fulfilled_order, fulfillment)
+
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.ORDER_FULFILLMENT_CONFIRMATION, payload=expected_payload
+ )
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_fulfillment_update(mocked_notify, fulfilled_order, site_settings):
+ fulfillment = fulfilled_order.fulfillments.first()
+ fulfillment.tracking_number = "https://www.example.com"
+ fulfillment.save()
+ manager = get_plugins_manager()
+
+ notifications.send_fulfillment_update(
+ order=fulfilled_order, fulfillment=fulfillment, manager=manager
+ )
+
+ expected_payload = get_default_fulfillment_payload(fulfilled_order, fulfillment)
+
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.ORDER_FULFILLMENT_UPDATE, expected_payload
+ )
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_email_order_canceled(mocked_notify, order, site_settings):
+ # given
+ manager = get_plugins_manager()
+
+ # when
+ notifications.send_order_canceled_confirmation(order, order.user, manager)
+
+ # then
+ expected_payload = {
+ "order": get_default_order_payload(order),
+ "recipient_email": order.get_customer_email(),
+ }
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.ORDER_CANCELED, expected_payload
+ )
+
+
[email protected]("saleor.plugins.manager.PluginsManager.notify")
+def test_send_email_order_refunded(mocked_notify, order, site_settings):
+ # given
+ manager = get_plugins_manager()
+ amount = order.total.gross.amount
+
+ # when
+ notifications.send_order_refunded_confirmation(
+ order, order.user, amount, order.currency, manager
+ )
+
+ # then
+ expected_payload = {
+ "order": get_default_order_payload(order),
+ "amount": amount,
+ "currency": order.currency,
+ "recipient_email": order.get_customer_email(),
+ }
+
+ mocked_notify.assert_called_once_with(
+ NotifyEventType.ORDER_REFUND_CONFIRMATION, expected_payload
+ )
diff --git a/saleor/order/tests/test_order.py b/saleor/order/tests/test_order.py
index b0394b70c5..14247e61f6 100644
--- a/saleor/order/tests/test_order.py
+++ b/saleor/order/tests/test_order.py
@@ -9,13 +9,17 @@ from ...discount.models import DiscountValueType, NotApplicable, Voucher, Vouche
from ...discount.utils import validate_voucher_in_order
from ...payment import ChargeStatus
from ...payment.models import Payment
+from ...plugins.manager import get_plugins_manager
from ...product.models import Collection
from ...warehouse.models import Stock
from ...warehouse.tests.utils import get_quantity_allocated_for_stock
from .. import OrderEvents, OrderStatus, models
-from ..emails import send_fulfillment_confirmation_to_customer
from ..events import OrderEvent, OrderEventsEmails, email_sent_event
from ..models import Order
+from ..notifications import (
+ get_default_fulfillment_payload,
+ send_fulfillment_confirmation_to_customer,
+)
from ..templatetags.order_lines import display_translated_order_line_name
from ..utils import (
add_variant_to_draft_order,
@@ -675,12 +679,12 @@ def test_ordered_item_change_quantity(transactional_db, order_with_lines):
assert order_with_lines.get_total_quantity() == 0
-@patch("saleor.order.actions.emails.send_fulfillment_confirmation")
+@patch("saleor.plugins.manager.PluginsManager.notify")
@pytest.mark.parametrize(
"has_standard,has_digital", ((True, True), (True, False), (False, True))
)
def test_send_fulfillment_order_lines_mails(
- mocked_send_fulfillment_confirmation,
+ mocked_notify,
staff_user,
fulfilled_order,
fulfillment,
@@ -688,7 +692,7 @@ def test_send_fulfillment_order_lines_mails(
has_standard,
has_digital,
):
-
+ manager = get_plugins_manager()
order = fulfilled_order
assert order.lines.count() == 2
@@ -705,12 +709,13 @@ def test_send_fulfillment_order_lines_mails(
line.save()
send_fulfillment_confirmation_to_customer(
- order=order, fulfillment=fulfillment, user=staff_user
+ order=order, fulfillment=fulfillment, user=staff_user, manager=manager
)
events = OrderEvent.objects.all()
- mocked_send_fulfillment_confirmation.delay.assert_called_once_with(
- order.pk, fulfillment.pk
+ expected_payload = get_default_fulfillment_payload(order, fulfillment)
+ mocked_notify.assert_called_once_with(
+ "order_fulfillment_confirmation", payload=expected_payload
)
# Ensure the standard fulfillment event was triggered
diff --git a/saleor/order/tests/test_order_actions.py b/saleor/order/tests/test_order_actions.py
index cea446f927..bd038419f7 100644
--- a/saleor/order/tests/test_order_actions.py
+++ b/saleor/order/tests/test_order_actions.py
@@ -21,6 +21,10 @@ from ..actions import (
order_refunded,
)
from ..models import Fulfillment
+from ..notifications import (
+ send_fulfillment_confirmation_to_customer,
+ send_payment_confirmation,
+)
@pytest.fixture
@@ -56,25 +60,33 @@ def order_with_digital_line(order, digital_content, stock, site_settings):
return order
-@patch("saleor.order.emails.send_fulfillment_confirmation.delay")
-@patch("saleor.order.emails.send_payment_confirmation.delay")
+@patch("saleor.order.actions.get_plugins_manager")
+@patch(
+ "saleor.order.actions.send_fulfillment_confirmation_to_customer",
+ wraps=send_fulfillment_confirmation_to_customer,
+)
+@patch(
+ "saleor.order.actions.send_payment_confirmation", wraps=send_payment_confirmation
+)
def test_handle_fully_paid_order_digital_lines(
mock_send_payment_confirmation,
- mock_send_fulfillment_confirmation,
+ send_fulfillment_confirmation_to_customer,
+ mocked_get_plugins_manager,
order_with_digital_line,
):
-
+ manager = mocked_get_plugins_manager()
order = order_with_digital_line
+ order.payments.add(Payment.objects.create())
handle_fully_paid_order(order)
fulfillment = order.fulfillments.first()
-
(
event_order_paid,
event_email_sent,
event_order_fulfilled,
event_digital_links,
) = order.events.all()
+
assert event_order_paid.type == OrderEvents.ORDER_FULLY_PAID
assert event_email_sent.type == OrderEvents.EMAIL_SENT
@@ -88,15 +100,21 @@ def test_handle_fully_paid_order_digital_lines(
event_digital_links.parameters["email_type"] == OrderEventsEmails.DIGITAL_LINKS
)
- mock_send_payment_confirmation.assert_called_once_with(order.pk)
- mock_send_fulfillment_confirmation.assert_called_once_with(order.pk, fulfillment.pk)
+ mock_send_payment_confirmation.assert_called_once_with(order, manager)
+ send_fulfillment_confirmation_to_customer.assert_called_once_with(
+ order, fulfillment, user=order.user, manager=manager
+ )
order.refresh_from_db()
assert order.status == OrderStatus.FULFILLED
-@patch("saleor.order.emails.send_payment_confirmation.delay")
-def test_handle_fully_paid_order(mock_send_payment_confirmation, order):
+@patch("saleor.order.actions.get_plugins_manager")
+@patch("saleor.order.actions.send_payment_confirmation")
+def test_handle_fully_paid_order(
+ mock_send_payment_confirmation, mocked_get_plugins_manager, order
+):
+ order.payments.add(Payment.objects.create())
handle_fully_paid_order(order)
event_order_paid, event_email_sent = order.events.all()
assert event_order_paid.type == OrderEvents.ORDER_FULLY_PAID
@@ -107,10 +125,12 @@ def test_handle_fully_paid_order(mock_send_payment_confirmation, order):
"email_type": OrderEventsEmails.PAYMENT,
}
- mock_send_payment_confirmation.assert_called_once_with(order.pk)
+ mock_send_payment_confirmation.assert_called_once_with(
+ order, mocked_get_plugins_manager()
+ )
-@patch("saleor.order.emails.send_payment_confirmation.delay")
+@patch("saleor.order.notifications.send_payment_confirmation")
def test_handle_fully_paid_order_no_email(mock_send_payment_confirmation, order):
order.user = None
order.user_email = ""
@@ -176,9 +196,11 @@ def test_cancel_fulfillment_variant_witout_inventory_tracking(
assert stock_quantity_before == line.order_line.variant.stocks.get().quantity
+@patch("saleor.order.actions.get_plugins_manager")
@patch("saleor.order.actions.send_order_canceled_confirmation")
def test_cancel_order(
send_order_canceled_confirmation_mock,
+ mocked_get_plugins_manager,
fulfilled_order_with_all_cancelled_fulfillments,
):
# given
@@ -200,12 +222,18 @@ def test_cancel_order(
order_line__order=order, quantity_allocated__gt=0
).exists()
- send_order_canceled_confirmation_mock.assert_called_once_with(order, None)
+ send_order_canceled_confirmation_mock.assert_called_once_with(
+ order, None, mocked_get_plugins_manager()
+ )
+@patch("saleor.order.actions.get_plugins_manager")
@patch("saleor.order.actions.send_order_refunded_confirmation")
def test_order_refunded(
- send_order_refunded_confirmation_mock, order, checkout_with_item,
+ send_order_refunded_confirmation_mock,
+ mocked_get_plugins_manager,
+ order,
+ checkout_with_item,
):
# given
payment = Payment.objects.create(
@@ -221,7 +249,7 @@ def test_order_refunded(
assert order_event.type == OrderEvents.PAYMENT_REFUNDED
send_order_refunded_confirmation_mock.assert_called_once_with(
- order, order.user, amount, payment.currency
+ order, order.user, amount, payment.currency, mocked_get_plugins_manager()
)
@@ -268,7 +296,7 @@ def test_fulfill_order_line_without_inventory_tracking(order_with_lines):
assert line.quantity_fulfilled == quantity_fulfilled_before + line.quantity
-@patch("saleor.order.actions.emails.send_fulfillment_confirmation")
+@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer")
@patch("saleor.order.utils.get_default_digital_content_settings")
def test_fulfill_digital_lines(
mock_digital_settings, mock_email_fulfillment, order_with_lines, media_root
@@ -294,4 +322,4 @@ def test_fulfill_digital_lines(
assert fulfillment_lines.count() == 1
assert line.digital_content_url
- assert mock_email_fulfillment.delay.called
+ assert mock_email_fulfillment.called
diff --git a/saleor/plugins/admin_email/emails.py b/saleor/plugins/admin_email/emails.py
index 3236ab6bef..5512876105 100644
--- a/saleor/plugins/admin_email/emails.py
+++ b/saleor/plugins/admin_email/emails.py
@@ -1,25 +1,31 @@
from .tasks import (
- send_email_with_link_to_download_file,
- send_export_failed_info,
+ send_email_with_link_to_download_file_task,
+ send_export_failed_email_task,
send_set_staff_password_email_task,
+ send_staff_order_confirmation_email_task,
)
def send_set_staff_password_email(payload):
+ recipient_email = payload["recipient_email"]
send_set_staff_password_email_task.delay(
- payload["email"], payload["redirect_url"], payload["token"]
+ recipient_email, payload["redirect_url"], payload["token"]
)
def send_csv_product_export_success(payload: dict):
- recipient_email = payload.get("user_email")
+ recipient_email = payload.get("recipient_email")
if recipient_email:
- send_email_with_link_to_download_file.delay(
+ send_email_with_link_to_download_file_task.delay(
recipient_email, payload["csv_link"]
)
+def send_staff_order_confirmation(payload: dict):
+ send_staff_order_confirmation_email_task.delay(payload)
+
+
def send_csv_export_failed(payload: dict):
- recipient_email = payload.get("user_email")
+ recipient_email = payload.get("recipient_email")
if recipient_email:
- send_export_failed_info.delay(recipient_email)
+ send_export_failed_email_task.delay(recipient_email)
diff --git a/saleor/plugins/admin_email/plugin.py b/saleor/plugins/admin_email/plugin.py
index 8343d4767e..4b2ff6ff87 100644
--- a/saleor/plugins/admin_email/plugin.py
+++ b/saleor/plugins/admin_email/plugin.py
@@ -3,11 +3,7 @@ from dataclasses import dataclass
from ...core.notify_events import AdminNotifyEvent, NotifyEventType
from ..base_plugin import BasePlugin
-from .emails import (
- send_csv_export_failed,
- send_csv_product_export_success,
- send_set_staff_password_email,
-)
+from . import emails
logger = logging.getLogger(__name__)
@@ -19,9 +15,10 @@ class UserEmailConfig:
event_map = {
- AdminNotifyEvent.ACCOUNT_SET_STAFF_PASSWORD: send_set_staff_password_email,
- AdminNotifyEvent.CSV_PRODUCT_EXPORT_SUCCESS: send_csv_product_export_success,
- AdminNotifyEvent.CSV_EXPORT_FAILED: send_csv_export_failed,
+ AdminNotifyEvent.STAFF_ORDER_CONFIRMATION: emails.send_staff_order_confirmation,
+ AdminNotifyEvent.ACCOUNT_SET_STAFF_PASSWORD: emails.send_set_staff_password_email,
+ AdminNotifyEvent.CSV_PRODUCT_EXPORT_SUCCESS: emails.send_csv_product_export_success,
+ AdminNotifyEvent.CSV_EXPORT_FAILED: emails.send_csv_export_failed,
}
diff --git a/saleor/plugins/admin_email/tasks.py b/saleor/plugins/admin_email/tasks.py
index 65afdb7175..84e9701611 100644
--- a/saleor/plugins/admin_email/tasks.py
+++ b/saleor/plugins/admin_email/tasks.py
@@ -26,7 +26,7 @@ def _send_set_password_email(recipient_email, password_set_url):
@app.task
-def send_email_with_link_to_download_file(recipient_email: str, csv_link: str):
+def send_email_with_link_to_download_file_task(recipient_email: str, csv_link: str):
send_kwargs, ctx = get_email_context()
ctx["csv_link"] = csv_link
send_templated_mail(
@@ -38,7 +38,7 @@ def send_email_with_link_to_download_file(recipient_email: str, csv_link: str):
@app.task
-def send_export_failed_info(recipient_email: str):
+def send_export_failed_email_task(recipient_email: str):
send_kwargs, ctx = get_email_context()
send_templated_mail(
template_name="csv/export_failed",
@@ -46,3 +46,15 @@ def send_export_failed_info(recipient_email: str):
context=ctx,
**send_kwargs,
)
+
+
+def send_staff_order_confirmation_email_task(payload):
+ send_kwargs, ctx = get_email_context()
+ payload.update(ctx)
+ send_templated_mail(
+ template_name="order/staff_confirm_order",
+ recipient_list=payload["recipient_list"],
+ context=payload,
+ **send_kwargs,
+ )
diff --git a/saleor/plugins/admin_email/tests/test_csv_emails.py b/saleor/plugins/admin_email/tests/test_csv_emails.py
index 8185ff8e1d..754ec83cdf 100644
--- a/saleor/plugins/admin_email/tests/test_csv_emails.py
+++ b/saleor/plugins/admin_email/tests/test_csv_emails.py
@@ -16,7 +16,7 @@ def test_send_email_with_link_to_download_file(
user_export_file.save()
# when
- emails.send_email_with_link_to_download_file(user_export_file) # noqa: F821
+ emails.send_email_with_link_to_download_file_task(user_export_file) # noqa: F821
# then
template = emails.EXPORT_TEMPLATES["export_products_success"] # noqa: F821
@@ -61,7 +61,7 @@ def test_send_export_failed_info(
expected_recipients = [user_export_file.user.email]
# when
- emails.send_export_failed_info(user_export_file) # noqa: F821
+ emails.send_export_failed_email_task(user_export_file) # noqa: F821
# then
template = emails.EXPORT_TEMPLATES["export_failed"] # noqa: F821
diff --git a/saleor/plugins/user_email/emails.py b/saleor/plugins/user_email/emails.py
index 1ee36d95e3..5d4446f785 100644
--- a/saleor/plugins/user_email/emails.py
+++ b/saleor/plugins/user_email/emails.py
@@ -1,73 +1,94 @@
-from ...account.models import User
from .tasks import (
send_account_confirmation_email_task,
send_account_delete_confirmation_email_task,
- send_invoice_task,
+ send_fulfillment_confirmation_email_task,
+ send_fulfillment_update_email_task,
+ send_invoice_email_task,
+ send_order_canceled_email_task,
+ send_order_confirmation_email_task,
+ send_order_refund_email_task,
send_password_reset_email_task,
+ send_payment_confirmation_email_task,
send_request_email_change_email_task,
send_set_user_password_email_task,
send_user_change_email_notification_task,
)
-REQUEST_EMAIL_CHANGE_TEMPLATE = "account/request_email_change"
-EMAIL_CHANGED_NOTIFICATION_TEMPLATE = "account/email_changed_notification"
-ACCOUNT_DELETE_TEMPLATE = "account/account_delete"
-PASSWORD_RESET_TEMPLATE = "account/password_reset"
-
-def get_default_user_payload(user: User):
- return {
- "email": user.email,
- "first_name": user.first_name,
- "last_name": user.last_name,
- "is_staff": user.is_staff,
- "is_active": user.is_active,
- "private_metadata": user.private_metadata,
- "metadata": user.metadata,
- }
-
-
-def handle_account_password_reset_event(payload):
+def send_account_password_reset_event(payload):
+ recipient_email = payload["recipient_email"]
+ user_payload = payload.get("user")
send_password_reset_email_task.delay(
- payload["email"], payload["redirect_url"], payload["id"], payload["token"]
+ recipient_email, payload["redirect_url"], user_payload["id"], payload["token"],
)
-def handle_account_confirmation(payload):
+def send_account_confirmation(payload):
+ recipient_email = payload["recipient_email"]
send_account_confirmation_email_task.delay(
- payload["email"], payload["token"], payload["redirect_url"]
+ recipient_email, payload["token"], payload["redirect_url"]
)
-def handle_account_change_email_request(payload):
+def send_account_change_email_request(payload):
+ recipient_email = payload["recipient_email"]
+ user_payload = payload.get("user")
send_request_email_change_email_task.delay(
- payload["new_email"],
+ recipient_email,
payload["old_email"],
payload["redirect_url"],
- payload["id"],
+ user_payload["id"],
payload["token"],
)
-def handle_account_change_email_confirm(payload):
- send_user_change_email_notification_task.delay(payload["old_email"])
+def send_account_change_email_confirm(payload):
+ recipient_email = payload["recipient_email"]
+ send_user_change_email_notification_task.delay(recipient_email)
-def handle_account_delete(payload):
+def send_account_delete(payload):
+ recipient_email = payload["recipient_email"]
send_account_delete_confirmation_email_task.delay(
- payload["email"], payload["redirect_url"], payload["token"]
+ recipient_email, payload["redirect_url"], payload["token"]
)
-def handle_account_set_customer_password(payload):
+def send_account_set_customer_password(payload):
+ recipient_email = payload["recipient_email"]
send_set_user_password_email_task.delay(
- payload["email"], payload["redirect_url"], payload["token"]
+ recipient_email, payload["redirect_url"], payload["token"]
)
-def handle_send_invoice(payload):
- send_invoice_task.delay(
- recipient_email=payload["recipient"],
+def send_invoice(payload):
+ recipient_email = payload["recipient_email"]
+ send_invoice_email_task.delay(
+ recipient_email=recipient_email,
invoice_number=payload["number"],
invoice_download_url=payload["download_url"],
)
+
+
+def send_order_confirmation(payload):
+ send_order_confirmation_email_task(payload=payload)
+
+
+def send_fulfillment_confirmation(payload):
+ send_fulfillment_confirmation_email_task(payload)
+
+
+def send_fulfillment_update(payload):
+ send_fulfillment_update_email_task(payload)
+
+
+def send_payment_confirmation(payload):
+ send_payment_confirmation_email_task(payload)
+
+
+def send_order_canceled(payload):
+ send_order_canceled_email_task.delay(payload)
+
+
+def send_order_refund(payload):
+ send_order_refund_email_task.delay(payload)
diff --git a/saleor/plugins/user_email/plugin.py b/saleor/plugins/user_email/plugin.py
index 403f0b8154..64b3083aa2 100644
--- a/saleor/plugins/user_email/plugin.py
+++ b/saleor/plugins/user_email/plugin.py
@@ -4,13 +4,19 @@ from dataclasses import dataclass
from ...core.notify_events import NotifyEventType, UserNotifyEvent
from ..base_plugin import BasePlugin
from .emails import (
- handle_account_change_email_confirm,
- handle_account_change_email_request,
- handle_account_confirmation,
- handle_account_delete,
- handle_account_password_reset_event,
- handle_account_set_customer_password,
- handle_send_invoice,
+ send_account_change_email_confirm,
+ send_account_change_email_request,
+ send_account_confirmation,
+ send_account_delete,
+ send_account_password_reset_event,
+ send_account_set_customer_password,
+ send_fulfillment_confirmation,
+ send_fulfillment_update,
+ send_invoice,
+ send_order_canceled,
+ send_order_confirmation,
+ send_order_refund,
+ send_payment_confirmation,
)
logger = logging.getLogger(__name__)
@@ -23,13 +29,19 @@ class UserEmailConfig:
event_map = {
- UserNotifyEvent.ACCOUNT_CONFIRMATION: handle_account_confirmation,
- UserNotifyEvent.ACCOUNT_SET_CUSTOMER_PASSWORD: handle_account_set_customer_password,
- UserNotifyEvent.ACCOUNT_DELETE: handle_account_delete,
- UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_CONFIRM: handle_account_change_email_confirm,
- UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_REQUEST: handle_account_change_email_request,
- UserNotifyEvent.ACCOUNT_PASSWORD_RESET: handle_account_password_reset_event,
- UserNotifyEvent.INVOICE_READY: handle_send_invoice,
+ UserNotifyEvent.ACCOUNT_CONFIRMATION: send_account_confirmation,
+ UserNotifyEvent.ACCOUNT_SET_CUSTOMER_PASSWORD: send_account_set_customer_password,
+ UserNotifyEvent.ACCOUNT_DELETE: send_account_delete,
+ UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_CONFIRM: send_account_change_email_confirm,
+ UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_REQUEST: send_account_change_email_request,
+ UserNotifyEvent.ACCOUNT_PASSWORD_RESET: send_account_password_reset_event,
+ UserNotifyEvent.INVOICE_READY: send_invoice,
+ UserNotifyEvent.ORDER_CONFIRMATION: send_order_confirmation,
+ UserNotifyEvent.ORDER_FULFILLMENT_CONFIRMATION: send_fulfillment_confirmation,
+ UserNotifyEvent.ORDER_FULFILLMENT_UPDATE: send_fulfillment_update,
+ UserNotifyEvent.ORDER_PAYMENT_CONFIRMATION: send_payment_confirmation,
+ UserNotifyEvent.ORDER_CANCELED: send_order_canceled,
+ UserNotifyEvent.ORDER_REFUND_CONFIRMATION: send_order_refund,
}
diff --git a/saleor/plugins/user_email/tasks.py b/saleor/plugins/user_email/tasks.py
index 8449c8d6a3..36533c6755 100644
--- a/saleor/plugins/user_email/tasks.py
+++ b/saleor/plugins/user_email/tasks.py
@@ -7,11 +7,6 @@ from ...celeryconf import app
from ...core.emails import get_email_context
from ...core.utils.url import prepare_url
-REQUEST_EMAIL_CHANGE_TEMPLATE = "account/request_email_change"
-EMAIL_CHANGED_NOTIFICATION_TEMPLATE = "account/email_changed_notification"
-ACCOUNT_DELETE_TEMPLATE = "account/account_delete"
-PASSWORD_RESET_TEMPLATE = "account/password_reset"
-
@app.task
def send_account_confirmation_email_task(email, token, redirect_url):
@@ -55,7 +50,7 @@ def send_request_email_change_email_task(
send_kwargs, ctx = get_email_context()
ctx["redirect_url"] = redirect_url
send_templated_mail(
- template_name=REQUEST_EMAIL_CHANGE_TEMPLATE,
+ template_name="account/request_email_change",
recipient_list=[new_email],
context=ctx,
**send_kwargs,
@@ -69,7 +64,7 @@ def send_request_email_change_email_task(
def send_user_change_email_notification_task(recipient_email):
send_kwargs, ctx = get_email_context()
send_templated_mail(
- template_name=EMAIL_CHANGED_NOTIFICATION_TEMPLATE,
+ template_name="account/email_changed_notification",
recipient_list=[recipient_email],
context=ctx,
**send_kwargs,
@@ -87,7 +82,7 @@ def _send_delete_confirmation_email(recipient_email, delete_url):
send_kwargs, ctx = get_email_context()
ctx["delete_url"] = delete_url
send_templated_mail(
- template_name=ACCOUNT_DELETE_TEMPLATE,
+ template_name="account/account_delete",
recipient_list=[recipient_email],
context=ctx,
**send_kwargs,
@@ -113,7 +108,7 @@ def _send_set_password_email(recipient_email, password_set_url):
@app.task
-def send_invoice_task(recipient_email, invoice_number, invoice_download_url):
+def send_invoice_email_task(recipient_email, invoice_number, invoice_download_url):
"""Send an invoice to user of related order with URL to download it."""
send_kwargs, ctx = get_email_context()
ctx["number"] = invoice_number
@@ -124,3 +119,81 @@ def send_invoice_task(recipient_email, invoice_number, invoice_download_url):
context=ctx,
**send_kwargs,
)
+
+
+def send_order_confirmation_email_task(payload):
+ """Send order confirmation email."""
+ recipient_email = payload["recipient_email"]
+ send_kwargs, ctx = get_email_context()
+ payload.update(ctx)
+ send_templated_mail(
+ template_name="order/confirm_order",
+ recipient_list=[recipient_email],
+ context=payload,
+ **send_kwargs,
+ )
+
+
+def send_fulfillment_confirmation_email_task(payload):
+ recipient_email = payload["recipient_email"]
+ send_kwargs, ctx = get_email_context()
+ payload.update(ctx)
+ send_templated_mail(
+ template_name="order/confirm_fulfillment",
+ recipient_list=[recipient_email],
+ context=payload,
+ **send_kwargs,
+ )
+
+
+def send_fulfillment_update_email_task(payload):
+ recipient_email = payload["recipient_email"]
+ send_kwargs, ctx = get_email_context()
+ payload.update(ctx)
+ send_templated_mail(
+ template_name="order/update_fulfillment",
+ recipient_list=[recipient_email],
+ context=payload,
+ **send_kwargs,
+ )
+
+
+def send_payment_confirmation_email_task(payload):
+ send_kwargs, ctx = get_email_context()
+ payload.update(ctx)
+ send_templated_mail(
+ template_name="order/payment/confirm_payment",
+ recipient_list=[payload["email"]],
+ context=payload,
+ **send_kwargs,
+ )
+
+
+def send_order_canceled_email_task(payload):
+ recipient_email = payload["recipient_email"]
+ send_kwargs, ctx = get_email_context()
+ payload.update(ctx)
+ send_templated_mail(
+ template_name="order/order_cancel",
+ recipient_list=[recipient_email],
+ context=payload,
+ **send_kwargs,
+ )
+
+
+def send_order_refund_email_task(payload):
+ recipient_email = payload["recipient_email"]
+ send_kwargs, ctx = get_email_context()
+ payload.update(ctx)
+ send_templated_mail(
+ template_name="order/order_refund",
+ recipient_list=[recipient_email],
+ context=payload,
+ **send_kwargs,
+ )
diff --git a/templates/templated_email/compiled/confirm_fulfillment.html b/templates/templated_email/compiled/confirm_fulfillment.html
index 2d380119d5..833136f367 100644
--- a/templates/templated_email/compiled/confirm_fulfillment.html
+++ b/templates/templated_email/compiled/confirm_fulfillment.html
@@ -203,7 +203,11 @@
<tbody>
{% for line in physical_lines %}
<tr class="table-item-row" style="border-bottom: 1px solid #D3D1D0;">
- <td style="padding: 5px;">{% display_translated_order_line_name line.order_line %}</td>
+ {% if line.order_line.variant_name %}
+ <td style="padding: 5px;">{{ line.order_line.product_name }} ({{line.order_line.variant_name }})</td>
+ {% else %}
+ <td style="padding: 5px;">{{ line.order_line.product_name }}</td>
+ {% endif %}
<td style="padding: 5px; text-align: right;" align="right">{{ line.quantity }}</td>
</tr>
{% endfor %}
@@ -221,9 +225,13 @@
<tbody>
{% for line in digital_lines %}
<tr class="table-item-row" style="border-bottom: 1px solid #D3D1D0;">
- <td style="padding: 5px;">{% display_translated_order_line_name line.order_line %}</td>
+ {% if line.order_line.variant_name %}
+ <td style="padding: 5px;">{{ line.order_line.product_name }} ({{line.order_line.variant_name }})</td>
+ {% else %}
+ <td style="padding: 5px;">{{ line.order_line.product_name }}</td>
+ {% endif %}
<td style="padding: 5px; text-align: right;" align="right">
- <a href="{{ line.order_line.digital_content_url.get_absolute_url }}">Link</a>
+ <a href="{{ line.order_line.digital_url }}">Link</a>
</td>
</tr>
{% endfor %}
diff --git a/templates/templated_email/compiled/confirm_order.html b/templates/templated_email/compiled/confirm_order.html
index fb30a47675..84c349e060 100644
--- a/templates/templated_email/compiled/confirm_order.html
+++ b/templates/templated_email/compiled/confirm_order.html
@@ -144,6 +144,7 @@
{% load display_translated_order_line_name from order_lines %}
{% load price from taxed_prices %}
+ {% load price_amount from taxed_prices %}
{% load voucher %}
<!--[if mso | IE]>
@@ -185,7 +186,7 @@
{% trans "Subtotal" context "E-mail order lines summary table" %}
</td>
<td style="padding: 5px; text-align: right;" align="right">
- {% price order.get_subtotal display_gross=order.display_gross_prices html=False %}
+ {% price_amount order.subtotal_net_amount order.subtotal_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
<tr>
@@ -193,7 +194,7 @@
{% trans "Shipping" context "E-mail order lines summary table" %}
</td>
<td style="padding: 5px; text-align: right;" align="right">
- {% price order.shipping_price display_gross=order.display_gross_prices html=False %}
+ {% price_amount order.shipping_price_net_amount order.shipping_price_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
<tr>
@@ -205,7 +206,7 @@
{% endif %}
</td>
<td style="padding: 5px; text-align: right;" align="right">
- {% price order.total.tax html=False %}
+ {% price_amount order.tax_amount order.tax_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
{% if order.discount_amount %}
@@ -223,7 +224,7 @@
<strong>{% trans "Total" context "E-mail order lines summary table" %}</strong>
</td>
<td style="padding: 5px; text-align: right;" align="right">
- <strong>{% price order.total display_gross=order.display_gross_prices html=False %}</strong>
+ <strong>{% price_amount order.total_net_amount order.total_gross_amount order.currency display_gross=order.display_gross_prices html=False %}</strong>
</td>
</tr>
</tfoot>
@@ -236,14 +237,18 @@
</tr>
</thead>
<tbody>
- {% for line in order %}
+ {% for line in order.lines %}
<tr class="table-item-row" style="border-bottom: 1px solid #D3D1D0;">
- <td style="padding: 5px;">{% display_translated_order_line_name line %}</td>
+ {% if line.variant_name %}
+ <td style="padding: 5px;">{{ line.product_name }} ({{line.variant_name }})</td>
+ {% else %}
+ <td style="padding: 5px;">{{ line.product_name }}</td>
+ {% endif %}
<td style="padding: 5px; text-align: right;" align="right">{{ line.quantity }}</td>
<td style="padding: 5px; text-align: right;" align="right">
- {% price line.unit_price display_gross=order.display_gross_prices html=False %}
+ {% price_amount line.unit_price_net_amount line.unit_price_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
- <td style="padding: 5px; text-align: right;" align="right">{% price line.get_total display_gross=order.display_gross_prices html=False %}</td>
+ <td style="padding: 5px; text-align: right;" align="right">{% price_amount line.total_net_amount line.total_gross_amount order.currency display_gross=order.display_gross_prices html=False %}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/templates/templated_email/compiled/order_cancel.html b/templates/templated_email/compiled/order_cancel.html
index 60bc4c7fad..216422a585 100644
--- a/templates/templated_email/compiled/order_cancel.html
+++ b/templates/templated_email/compiled/order_cancel.html
@@ -103,8 +103,8 @@
<tr>
<td align="left" style="font-size: 0px; padding: 10px 25px; word-break: break-word;">
- <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">{% blocktrans trimmed context "Order cancel e-mail text" %}
- Your order has been canceled.
+ <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">{% blocktrans trimmed with id=order.id context "Order cancel e-mail text" %}
+ Your order #{{ id }} has been canceled.
{% endblocktrans %}</div>
</td>
diff --git a/templates/templated_email/compiled/staff_confirm_order.html b/templates/templated_email/compiled/staff_confirm_order.html
index c9d982b941..a25640b94b 100644
--- a/templates/templated_email/compiled/staff_confirm_order.html
+++ b/templates/templated_email/compiled/staff_confirm_order.html
@@ -104,7 +104,7 @@
<tr>
<td align="left" style="font-size: 0px; padding: 10px 25px; word-break: break-word;">
- <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">{% blocktrans trimmed context "Order confirmation staff e-mail text" %}
+ <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">{% blocktrans trimmed with order_details_url=order.order_details_url context "Order confirmation staff e-mail text" %}
Someone placed a new order in your store. To see order details please visit: <a href="{{ order_details_url }}">{{ order_details_url }}</a>
{% endblocktrans %}</div>
@@ -138,6 +138,7 @@
{% load display_translated_order_line_name from order_lines %}
{% load price from taxed_prices %}
+ {% load price_amount from taxed_prices %}
{% load voucher %}
<!--[if mso | IE]>
@@ -179,7 +180,7 @@
{% trans "Subtotal" context "E-mail order lines summary table" %}
</td>
<td style="padding: 5px; text-align: right;" align="right">
- {% price order.get_subtotal display_gross=order.display_gross_prices html=False %}
+ {% price_amount order.subtotal_net_amount order.subtotal_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
<tr>
@@ -187,7 +188,7 @@
{% trans "Shipping" context "E-mail order lines summary table" %}
</td>
<td style="padding: 5px; text-align: right;" align="right">
- {% price order.shipping_price display_gross=order.display_gross_prices html=False %}
+ {% price_amount order.shipping_price_net_amount order.shipping_price_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
<tr>
@@ -199,7 +200,7 @@
{% endif %}
</td>
<td style="padding: 5px; text-align: right;" align="right">
- {% price order.total.tax html=False %}
+ {% price_amount order.tax_amount order.tax_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
{% if order.discount_amount %}
@@ -217,7 +218,7 @@
<strong>{% trans "Total" context "E-mail order lines summary table" %}</strong>
</td>
<td style="padding: 5px; text-align: right;" align="right">
- <strong>{% price order.total display_gross=order.display_gross_prices html=False %}</strong>
+ <strong>{% price_amount order.total_net_amount order.total_gross_amount order.currency display_gross=order.display_gross_prices html=False %}</strong>
</td>
</tr>
</tfoot>
@@ -230,14 +231,18 @@
</tr>
</thead>
<tbody>
- {% for line in order %}
+ {% for line in order.lines %}
<tr class="table-item-row" style="border-bottom: 1px solid #D3D1D0;">
- <td style="padding: 5px;">{% display_translated_order_line_name line %}</td>
+ {% if line.variant_name %}
+ <td style="padding: 5px;">{{ line.product_name }} ({{line.variant_name }})</td>
+ {% else %}
+ <td style="padding: 5px;">{{ line.product_name }}</td>
+ {% endif %}
<td style="padding: 5px; text-align: right;" align="right">{{ line.quantity }}</td>
<td style="padding: 5px; text-align: right;" align="right">
- {% price line.unit_price display_gross=order.display_gross_prices html=False %}
+ {% price_amount line.unit_price_net_amount line.unit_price_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
- <td style="padding: 5px; text-align: right;" align="right">{% price line.get_total display_gross=order.display_gross_prices html=False %}</td>
+ <td style="padding: 5px; text-align: right;" align="right">{% price_amount line.total_net_amount line.total_gross_amount order.currency display_gross=order.display_gross_prices html=False %}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/templates/templated_email/compiled/update_fulfillment.html b/templates/templated_email/compiled/update_fulfillment.html
index 9af08627d5..8386981ce6 100644
--- a/templates/templated_email/compiled/update_fulfillment.html
+++ b/templates/templated_email/compiled/update_fulfillment.html
@@ -191,7 +191,11 @@
<tbody>
{% for line in physical_lines %}
<tr class="table-item-row" style="border-bottom: 1px solid #D3D1D0;">
- <td style="padding: 5px;">{% display_translated_order_line_name line.order_line %}</td>
+ {% if line.order_line.variant_name %}
+ <td style="padding: 5px;">{{ line.order_line.product_name }} ({{line.order_line.variant_name }})</td>
+ {% else %}
+ <td style="padding: 5px;">{{ line.order_line.product_name }}</td>
+ {% endif %}
<td style="padding: 5px; text-align: right;" align="right">{{ line.quantity }}</td>
</tr>
{% endfor %}
@@ -209,9 +213,13 @@
<tbody>
{% for line in digital_lines %}
<tr class="table-item-row" style="border-bottom: 1px solid #D3D1D0;">
- <td style="padding: 5px;">{% display_translated_order_line_name line.order_line %}</td>
+ {% if line.order_line.variant_name %}
+ <td style="padding: 5px;">{{ line.order_line.product_name }} ({{line.order_line.variant_name }})</td>
+ {% else %}
+ <td style="padding: 5px;">{{ line.order_line.product_name }}</td>
+ {% endif %}
<td style="padding: 5px; text-align: right;" align="right">
- <a href="{{ line.order_line.digital_content_url.get_absolute_url }}">Link</a>
+ <a href="{{ line.order_line.digital_url }}">Link</a>
</td>
</tr>
{% endfor %}
diff --git a/templates/templated_email/order/confirm_fulfillment.email b/templates/templated_email/order/confirm_fulfillment.email
index be6ee7d971..419171f60c 100644
--- a/templates/templated_email/order/confirm_fulfillment.email
+++ b/templates/templated_email/order/confirm_fulfillment.email
@@ -1,8 +1,8 @@
{% load i18n %}
{% block subject %}
- {% blocktrans trimmed with order=fulfillment.order context "Fulfillment confirmation email subject" %}
- Your order {{ order }} has been fulfilled
+ {% blocktrans trimmed with id=order.id context "Fulfillment confirmation email subject" %}
+ Your order {{ id }} has been fulfilled
{% endblocktrans %}
{% endblock %}
@@ -18,11 +18,11 @@ You can track your shipment with {{ tracking_number }} code.
{% endif %}
{% for line in physical_lines %}
-{{ line.quantity }} x {{ line.order_line }}
+{{ line.quantity }} x {{ line.order_line.product_name }} {{line.order_line.variant_name }}
{% endfor %}
{% for line in digital_lines %}
-{{ line.quantity }} x {{ line.order_line.digital_content_url.get_absolute_url }}
+{{ line.quantity }} x {{ line.order_line.digital_url }}
{% endfor %}
{% include 'templated_email/shared/_footer.email' %}
diff --git a/templates/templated_email/order/confirm_order.email b/templates/templated_email/order/confirm_order.email
index d1141c6af7..d61e4f5c74 100644
--- a/templates/templated_email/order/confirm_order.email
+++ b/templates/templated_email/order/confirm_order.email
@@ -1,10 +1,11 @@
{% load i18n %}
+{% load price_amount from taxed_prices %}
{% load price from taxed_prices %}
{% load voucher %}
{% block subject %}
- {% blocktrans trimmed context "Order confirmation e-mail subject" %}
- Order {{ order }} details
+ {% blocktrans trimmed with id=order.id context "Order confirmation e-mail subject" %}
+ Order #{{ id }} details
{% endblocktrans %}
{% endblock %}
@@ -19,21 +20,21 @@ To see your payment details please visit:
{{ order_details_url }}
{% endblocktrans %}
{% endif %}
-{% for line in order %}
-{{ line.quantity }} x {{ line }}, {% price line.get_total display_gross=order.display_gross_prices html=False %}
+{% for line in order.lines %}
+{{ line.quantity }} x {{ line.product_name }}, {% price_amount line.unit_price_net_amount line.unit_price_gross_amount currency display_gross=display_gross_prices html=False %}
{% endfor %}
{% trans "Order summary" context "Order confirmation e-mail table header" %}:
-{% trans "Subtotal" context "Order confirmation e-mail table header" %}: {% price order.get_subtotal display_gross=order.display_gross_prices html=False %}
-{% trans "Shipping" context "Order confirmation e-mail table header" %}: {% price order.shipping_price display_gross=order.display_gross_prices html=False %}
-{% if order.display_gross_prices %}{% trans "Taxes (included)" context "Order confirmation e-mail table header" %}{% else %}{% trans "Taxes" context "Order confirmation e-mail table header" %}{% endif %}: {% price order.total.tax html=False %}
+{% trans "Subtotal" context "Order confirmation e-mail table header" %}: {% price_amount order.subtotal_net_amount order.subtotal_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
+{% trans "Shipping" context "Order confirmation e-mail table header" %}: {% price_amount order.shipping_price_net_amount order.shipping_price_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
+{% if order.display_gross_prices %}{% trans "Taxes (included)" context "Order confirmation e-mail table header" %}{% else %}{% trans "Taxes" context "Order confirmation e-mail table header" %}{% endif %}: {% price_amount order.tax_amount order.tax_amount currency display_gross=order.display_gross_prices html=False %}
{% if order.discount_amount %}{% trans "Discount:" context "Order confirmation e-mail table header" %} {% discount_as_negative order.discount %}{% endif %}
-{% trans "Total" context "Order confirmation e-mail table header" %}: {% price order.total.gross html=False %}
+{% trans "Total" context "Order confirmation e-mail table header" %}: {% price_amount order.total_net_amount order.total_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
{% trans "Billing address" context "Order confirmation e-mail billing address" %}
-{% if order.billing_address %}{{ order.billing_address }}{% else %}{% trans "No billing address" context "Order confirmation e-mail text" %}{% endif %}
+{% if order.billing_address %}{{ order.billing_address.first_name }}, {{ order.billing_address.last_name }}, {{ order.billing_address.company_name }}, {{ order.billing_address.street_address_1 }}, {{ order.billing_address.street_address_2 }}, {{ order.billing_address.city }}, {{ order.billing_address.city_area }}, {{ order.billing_address.postal_code }}, {{ order.billing_address.country }}, {{ order.billing_address.country_area }}, {{ order.billing_address.phone }}{% else %}{% trans "No billing address" context "Order confirmation e-mail text" %}{% endif %}
{% trans "Shipping address" context "Order confirmation e-mail shipping address" %}
-{% if order.shipping_address %}{{ order.shipping_address }}{% else %}{% trans "No shipping required" context "Order confirmation e-mail text" %}{% endif %}
+{% if order.shipping_address %}{{ order.shipping_address.first_name }}, {{ order.shipping_address.last_name }}, {{ order.shipping_address.company_name }}, {{ order.shipping_address.street_address_1 }}, {{ order.shipping_address.street_address_2 }}, {{ order.shipping_address.city }}, {{ order.shipping_address.city_area }}, {{ order.shipping_address.postal_code }}, {{ order.shipping_address.country }}, {{ order.shipping_address.country_area }}, {{ order.shipping_address.phone }}{% else %}{% trans "No shipping required" context "Order confirmation e-mail text" %}{% endif %}
{% include 'templated_email/shared/_footer.email' %}
{% endblock %}
diff --git a/templates/templated_email/order/order_cancel.email b/templates/templated_email/order/order_cancel.email
index eefc47c573..132dc5e13b 100644
--- a/templates/templated_email/order/order_cancel.email
+++ b/templates/templated_email/order/order_cancel.email
@@ -1,15 +1,15 @@
{% load i18n %}
{% block subject %}
- {% blocktrans trimmed context "Order cancel e-mail subject" %}
- Order {{ order }} canceled
+ {% blocktrans trimmed with id=order.id context "Order cancel e-mail subject" %}
+ Order {{ id }} canceled
{% endblocktrans %}
{% endblock %}
{% block plain %}
{% include 'templated_email/shared/_header.email' %}
-{% blocktrans context "Order cancel e-mail text" %}
-Your order has been canceled.
+{% blocktrans trimmed with id=order.id context "Order cancel e-mail text" %}
+Your order #{{ id }} has been canceled.
{% endblocktrans %}
{% include 'templated_email/shared/_footer.email' %}
diff --git a/templates/templated_email/order/order_refund.email b/templates/templated_email/order/order_refund.email
index 0debd10955..88031dfbf7 100644
--- a/templates/templated_email/order/order_refund.email
+++ b/templates/templated_email/order/order_refund.email
@@ -1,8 +1,8 @@
{% load i18n %}
{% block subject %}
- {% blocktrans trimmed context "Order refund e-mail subject" %}
- Order {{ order }} refunded
+ {% blocktrans trimmed with id=order.id context "Order refund e-mail subject" %}
+ Order {{ id }} refunded
{% endblocktrans %}
{% endblock %}
diff --git a/templates/templated_email/order/payment/confirm_payment.email b/templates/templated_email/order/payment/confirm_payment.email
index acb5730f38..24e2743ea8 100644
--- a/templates/templated_email/order/payment/confirm_payment.email
+++ b/templates/templated_email/order/payment/confirm_payment.email
@@ -1,8 +1,8 @@
{% load i18n %}
{% block subject %}
- {% blocktrans trimmed context "Payment confirmation subject" %}
- Order {{ order }} payment details
+ {% blocktrans trimmed with id=order.id context "Payment confirmation subject" %}
+ Order {{ id }} payment details
{% endblocktrans %}
{% endblock %}
diff --git a/templates/templated_email/order/staff_confirm_order.email b/templates/templated_email/order/staff_confirm_order.email
index 689d8731a4..ee235599a2 100644
--- a/templates/templated_email/order/staff_confirm_order.email
+++ b/templates/templated_email/order/staff_confirm_order.email
@@ -1,10 +1,11 @@
{% load i18n %}
{% load price from taxed_prices %}
+{% load price_amount from taxed_prices %}
{% load voucher %}
{% block subject %}
- {% blocktrans trimmed context "Order confirmation e-mail subject" %}
- Order {{ order }} details
+ {% blocktrans trimmed with id=order.id context "Order confirmation e-mail subject" %}
+ Order {{ id }} details
{% endblocktrans %}
{% endblock %}
@@ -13,27 +14,26 @@
{% blocktrans context "Order confirmation staff e-mail text" %}
Below is the list of ordered products.
{% endblocktrans %}
-{% if order_details_url %}
-{% blocktrans context "Order confirmation e-mail payment details" %}
-To see your payment details please visit:
-{{ order_details_url }}
+{% if order.order_details_url %}
+{% blocktrans trimmed with order_details_url=order.order_details_url context "Order confirmation staff e-mail text" %}
+Someone placed a new order in your store. To see order details please visit: {{ order_details_url }}
{% endblocktrans %}
{% endif %}
-{% for line in order %}
-{{ line.quantity }} x {{ line }}, {% price line.get_total display_gross=order.display_gross_prices html=False %}
+{% for line in order.lines %}
+{{ line.quantity }} x {{ line.product_name }}, {% price_amount line.unit_price_net_amount line.unit_price_gross_amount order.currency display_gross=display_gross_prices html=False %}
{% endfor %}
{% trans "Order summary" context "Order confirmation e-mail table header" %}:
-{% trans "Subtotal" context "Order confirmation e-mail table header" %}: {% price order.get_subtotal display_gross=order.display_gross_prices html=False %}
-{% trans "Shipping" context "Order confirmation e-mail table header" %}: {% price order.shipping_price display_gross=order.display_gross_prices html=False %}
-{% if order.display_gross_prices %}{% trans "Taxes (included)" context "Order confirmation e-mail table header" %}{% else %}{% trans "Taxes" context "Order confirmation e-mail table header" %}{% endif %}: {% price order.total.tax html=False %}
+{% trans "Subtotal" context "Order confirmation e-mail table header" %}: {% price_amount order.subtotal_net_amount order.subtotal_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
+{% trans "Shipping" context "Order confirmation e-mail table header" %}: {% price_amount order.shipping_price_net_amount order.shipping_price_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
+{% if order.display_gross_prices %}{% trans "Taxes (included)" context "Order confirmation e-mail table header" %}{% else %}{% trans "Taxes" context "Order confirmation e-mail table header" %}{% endif %}: {% price_amount order.tax_amount order.tax_amount order.currency display_gross=order.display_gross_prices html=False %}
{% if order.discount_amount %}{% trans "Discount:" context "Order confirmation e-mail table header" %} {% discount_as_negative order.discount %}{% endif %}
-{% trans "Total" context "Order confirmation e-mail table header" %}: {% price order.total.gross html=False %}
+{% trans "Total" context "Order confirmation e-mail table header" %}: {% price_amount order.total_net_amount order.total_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
{% trans "Billing address" context "Order confirmation e-mail billing address" %}
-{% if order.billing_address %}{{ order.billing_address }}{% else %}{% trans "No billing address" context "Order confirmation e-mail text" %}{% endif %}
+{% if order.billing_address %}{{ order.billing_address.first_name }}, {{ order.billing_address.last_name }}, {{ order.billing_address.company_name }}, {{ order.billing_address.street_address_1 }}, {{ order.billing_address.street_address_2 }}, {{ order.billing_address.city }}, {{ order.billing_address.city_area }}, {{ order.billing_address.postal_code }}, {{ order.billing_address.country }}, {{ order.billing_address.country_area }}, {{ order.billing_address.phone }}{% else %}{% trans "No billing address" context "Order confirmation e-mail text" %}{% endif %}
{% trans "Shipping address" context "Order confirmation e-mail shipping address" %}
-{% if order.shipping_address %}{{ order.shipping_address }}{% else %}{% trans "No shipping required" context "Order confirmation e-mail text" %}{% endif %}
+{% if order.shipping_address %}{{ order.shipping_address.first_name }}, {{ order.shipping_address.last_name }}, {{ order.shipping_address.company_name }}, {{ order.shipping_address.street_address_1 }}, {{ order.shipping_address.street_address_2 }}, {{ order.shipping_address.city }}, {{ order.shipping_address.city_area }}, {{ order.shipping_address.postal_code }}, {{ order.shipping_address.country }}, {{ order.shipping_address.country_area }}, {{ order.shipping_address.phone }}{% else %}{% trans "No shipping required" context "Order confirmation e-mail text" %}{% endif %}
{% include 'templated_email/shared/_footer.email' %}
{% endblock %}
diff --git a/templates/templated_email/order/update_fulfillment.email b/templates/templated_email/order/update_fulfillment.email
index e54acd39e8..a4e1e4c7fb 100644
--- a/templates/templated_email/order/update_fulfillment.email
+++ b/templates/templated_email/order/update_fulfillment.email
@@ -1,8 +1,8 @@
{% load i18n %}
{% block subject %}
- {% blocktrans trimmed with order=fulfillment.order context "Fulfillment update email subject" %}
- Shipping update for order {{ order }}
+ {% blocktrans trimmed with id=order.id context "Fulfillment update email subject" %}
+ Shipping update for order {{ id }}
{% endblocktrans %}
{% endblock %}
@@ -17,8 +17,8 @@ You can track your shipment with the following code: {{ tracking_number }}.
{% endblocktrans %}
{% endif %}
-{% for line in fulfillment %}
-{{ line.quantity }} x {{ line.order_line }}
+{% for line in physical_lines %}
+{{ line.quantity }} x {{ line.order_line.product_name }} {{line.order_line.variant_name }}
{% endfor %}
{% include 'templated_email/shared/_footer.email' %}
diff --git a/templates/templated_email/source/order_cancel.mjml b/templates/templated_email/source/order_cancel.mjml
index 748568ef24..85f41c4ff3 100644
--- a/templates/templated_email/source/order_cancel.mjml
+++ b/templates/templated_email/source/order_cancel.mjml
@@ -13,8 +13,8 @@
{% trans "Hi!" context "Standard e-mail greeting" %}
</mj-text>
<mj-text>
- {% blocktrans trimmed context "Order cancel e-mail text" %}
- Your order has been canceled.
+ {% blocktrans trimmed with id=order.id context "Order cancel e-mail text" %}
+ Your order #{{ id }} has been canceled.
{% endblocktrans %}
</mj-text>
</mj-column>
diff --git a/templates/templated_email/source/partials/_fulfillment_lines.mjml b/templates/templated_email/source/partials/_fulfillment_lines.mjml
index 0ae5e32c90..96822f8ddb 100644
--- a/templates/templated_email/source/partials/_fulfillment_lines.mjml
+++ b/templates/templated_email/source/partials/_fulfillment_lines.mjml
@@ -15,7 +15,11 @@
<tbody>
{% for line in physical_lines %}
<tr class="table-item-row">
- <td>{% display_translated_order_line_name line.order_line %}</td>
+ {% if line.order_line.variant_name %}
+ <td>{{ line.order_line.product_name }} ({{line.order_line.variant_name }})</td>
+ {% else %}
+ <td>{{ line.order_line.product_name }}</td>
+ {% endif %}
<td style="text-align: right;">{{ line.quantity }}</td>
</tr>
{% endfor %}
@@ -33,9 +37,13 @@
<tbody>
{% for line in digital_lines %}
<tr class="table-item-row">
- <td>{% display_translated_order_line_name line.order_line %}</td>
+ {% if line.order_line.variant_name %}
+ <td>{{ line.order_line.product_name }} ({{line.order_line.variant_name }})</td>
+ {% else %}
+ <td>{{ line.order_line.product_name }}</td>
+ {% endif %}
<td style="text-align: right;">
- <a href={{ line.order_line.digital_content_url.get_absolute_url }}>Link</a>
+ <a href={{ line.order_line.digital_url }}>Link</a>
</td>
</tr>
{% endfor %}
diff --git a/templates/templated_email/source/partials/_order_lines.mjml b/templates/templated_email/source/partials/_order_lines.mjml
index a1cdb3b838..da6dae2bad 100644
--- a/templates/templated_email/source/partials/_order_lines.mjml
+++ b/templates/templated_email/source/partials/_order_lines.mjml
@@ -1,6 +1,7 @@
<mj-raw>
{% load display_translated_order_line_name from order_lines %}
{% load price from taxed_prices %}
+ {% load price_amount from taxed_prices %}
{% load voucher %}
</mj-raw>
<mj-section>
@@ -12,7 +13,7 @@
{% trans "Subtotal" context "E-mail order lines summary table" %}
</td>
<td style="text-align: right;">
- {% price order.get_subtotal display_gross=order.display_gross_prices html=False %}
+ {% price_amount order.subtotal_net_amount order.subtotal_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
<tr>
@@ -20,7 +21,7 @@
{% trans "Shipping" context "E-mail order lines summary table" %}
</td>
<td style="text-align: right;">
- {% price order.shipping_price display_gross=order.display_gross_prices html=False %}
+ {% price_amount order.shipping_price_net_amount order.shipping_price_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
<tr>
@@ -32,7 +33,7 @@
{% endif %}
</td>
<td style="text-align: right;">
- {% price order.total.tax html=False %}
+ {% price_amount order.tax_amount order.tax_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
</tr>
{% if order.discount_amount %}
@@ -50,7 +51,7 @@
<strong>{% trans "Total" context "E-mail order lines summary table" %}</strong>
</td>
<td style="text-align: right;">
- <strong>{% price order.total display_gross=order.display_gross_prices html=False %}</strong>
+ <strong>{% price_amount order.total_net_amount order.total_gross_amount order.currency display_gross=order.display_gross_prices html=False %}</strong>
</td>
</tr>
</tfoot>
@@ -63,14 +64,18 @@
</tr>
</thead>
<tbody>
- {% for line in order %}
+ {% for line in order.lines %}
<tr class="table-item-row">
- <td>{% display_translated_order_line_name line %}</td>
+ {% if line.variant_name %}
+ <td>{{ line.product_name }} ({{line.variant_name }})</td>
+ {% else %}
+ <td>{{ line.product_name }}</td>
+ {% endif %}
<td style="text-align: right;">{{ line.quantity }}</td>
<td style="text-align: right;">
- {% price line.unit_price display_gross=order.display_gross_prices html=False %}
+ {% price_amount line.unit_price_net_amount line.unit_price_gross_amount order.currency display_gross=order.display_gross_prices html=False %}
</td>
- <td style="text-align: right;">{% price line.get_total display_gross=order.display_gross_prices html=False %}</td>
+ <td style="text-align: right;">{% price_amount line.total_net_amount line.total_gross_amount order.currency display_gross=order.display_gross_prices html=False %}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/templates/templated_email/source/staff_confirm_order.mjml b/templates/templated_email/source/staff_confirm_order.mjml
index 1c527c850f..f68df260a6 100644
--- a/templates/templated_email/source/staff_confirm_order.mjml
+++ b/templates/templated_email/source/staff_confirm_order.mjml
@@ -14,7 +14,7 @@
{% trans "Hi!" context "Standard e-mail greeting" %}
</mj-text>
<mj-text>
- {% blocktrans trimmed context "Order confirmation staff e-mail text" %}
+ {% blocktrans trimmed with order_details_url=order.order_details_url context "Order confirmation staff e-mail text" %}
Someone placed a new order in your store. To see order details please visit: <a href="{{ order_details_url }}">{{ order_details_url }}</a>
{% endblocktrans %}
</mj-text>