Skip to content

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

Send shipping update email

Anna Siwik2ec575ff4656
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 08185c8edf..b45c827d04 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -228,6 +228,12 @@ class CancelFulfillmentForm(forms.Form):
class FulfillmentTrackingNumberForm(forms.ModelForm):
+ """Update tracking number in fulfillment group."""
+ send_mail = forms.BooleanField(
+ initial=True, required=False, label=pgettext_lazy(
+ 'Send mail to customer',
+ 'Send notification email to customer'))
+
class Meta:
model = Fulfillment
fields = ['tracking_number']
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index b78d2b4973..f280d00c71 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -15,7 +15,7 @@ from prices import Money, TaxedMoney
from ...core.exceptions import InsufficientStock
from ...core.utils import ZERO_TAXED_MONEY, get_paginator_items
from ...order import OrderStatus
-from ...order.emails import send_fulfillment_confirmation
+from ...order.emails import send_fulfillment_confirmation, send_fulfillment_update
from ...order.models import (
FulfillmentLine, Fulfillment, Order, OrderLine, OrderNote)
from ...order.utils import update_order_status
@@ -498,6 +498,13 @@ def change_fulfillment_tracking(request, order_pk, fulfillment_pk):
'Fulfillment #%(fulfillment)s tracking number removed') % {
'fulfillment': fulfillment.composed_id}
order.history.create(content=msg, user=request.user)
+ if form.cleaned_data.get('send_mail'):
+ send_fulfillment_update.delay(order.pk, fulfillment.pk)
+ send_mail_msg = pgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Shipping update email was sent to user (%(email)s)') % {
+ 'email': order.get_user_current_email()}
+ order.history.create(content=send_mail_msg, user=request.user)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
elif form.errors:
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
index 15bca34047..dc3902ca94 100644
--- a/saleor/order/emails.py
+++ b/saleor/order/emails.py
@@ -9,6 +9,7 @@ from .models import Fulfillment, Order
CONFIRM_ORDER_TEMPLATE = 'source/order/confirm_order'
CONFIRM_FULFILLMENT_TEMPLATE = 'source/order/confirm_fulfillment'
+UPDATE_FULFILLMENT_TEMPLATE = 'source/order/update_fulfillment'
CONFIRM_PAYMENT_TEMPLATE = 'source/order/payment/confirm_payment'
CONFIRM_NOTE_TEMPLATE = 'source/order/note/confirm_note'
@@ -53,6 +54,14 @@ def send_fulfillment_confirmation(order_pk, fulfillment_pk):
_send_confirmation(**email_data)
+@shared_task
+def send_fulfillment_update(order_pk, fulfillment_pk):
+ email_data = collect_data_for_email(order_pk, UPDATE_FULFILLMENT_TEMPLATE)
+ fulfillment = Fulfillment.objects.get(pk=fulfillment_pk)
+ email_data.update({'context': {'fulfillment': fulfillment}})
+ _send_confirmation(**email_data)
+
+
@shared_task
def send_payment_confirmation(order_pk):
email_data = collect_data_for_email(order_pk, CONFIRM_PAYMENT_TEMPLATE)
diff --git a/templates/dashboard/order/modal/change_fulfillment_tracking.html b/templates/dashboard/order/modal/change_fulfillment_tracking.html
index ccec1cb93a..89b7c903b9 100644
--- a/templates/dashboard/order/modal/change_fulfillment_tracking.html
+++ b/templates/dashboard/order/modal/change_fulfillment_tracking.html
@@ -22,6 +22,7 @@
{% block content %}
<div class="col s12">
{{ form.tracking_number|materializecss }}
+ {{ form.send_mail|materializecss }}
</div>
{% endblock %}
diff --git a/templates/templated_email/source/order/update_fulfillment.email b/templates/templated_email/source/order/update_fulfillment.email
new file mode 100644
index 0000000000..842faae47c
--- /dev/null
+++ b/templates/templated_email/source/order/update_fulfillment.email
@@ -0,0 +1,36 @@
+{% load i18n %}
+{% load gross from prices_i18n %}
+
+{% block subject %}
+ {% blocktrans trimmed with order=fulfillment.order context "Fulfillment update email subject" %}
+ Shipping update for order {{ order }}
+ {% endblocktrans %}
+{% endblock %}
+
+{% block plain %}
+{% blocktrans context "Fulfillment update email text" %}
+Hi!
+
+Your shipping status has been updated. Below is the list of ordered products that have been updated with new tracking number.
+{% endblocktrans %}
+{% if fulfillment.tracking_number %}
+{% blocktrans trimmed with tracking_number=fulfillment.tracking_number context "Fulfillment update email text" %}
+You can track your shipment with {{ tracking_number }} code.
+{% endblocktrans %}
+{% endif %}
+
+{% for line in fulfillment %}
+{{ line.quantity }} x {{ line.order_line.product_name }}
+{% endfor %}
+
+{% blocktrans context "Fulfillment update email text" %}
+This is an automatically generated email, please do not reply.
+
+Sincerely,
+{{ site_name }}
+{% endblocktrans %}
+{% endblock %}
+
+{% block html %}
+{% include 'templated_email/compiled/update_fulfillment.html' %}
+{% endblock %}
diff --git a/templates/templated_email/source/order/update_fulfillment.mjml b/templates/templated_email/source/order/update_fulfillment.mjml
new file mode 100644
index 0000000000..f59fbdcb17
--- /dev/null
+++ b/templates/templated_email/source/order/update_fulfillment.mjml
@@ -0,0 +1,36 @@
+<mjml>
+ <mj-head>
+ <mj-include path="../shared/styles" />
+ </mj-head>
+ <mj-body>
+ <mj-container>
+ <mj-section css-class="no-display">
+ <mj-column>
+ <mj-text>
+ {% load i18n %}
+ </mj-text>
+ </mj-column>
+ </mj-section>
+ <mj-include path="../shared/header" />
+ <mj-section>
+ <mj-column>
+ <mj-text font-size="16px">
+ {% trans "Hi!" context "Fulfillment update email text" %}
+ </mj-text>
+ <mj-text>
+ {% blocktrans trimmed context "Fulfillment update email text" %}
+ Your shipping status has been updated. Below is the list of ordered products that have been updated with new tracking number.
+ {% endblocktrans %}
+ {% if fulfillment.tracking_number %}
+ {% blocktrans trimmed with tracking_number=fulfillment.tracking_number context "Fulfillment update email text" %}
+ You can track your shipment with {{ tracking_number }} code.
+ {% endblocktrans %}
+ {% endif %}
+ </mj-text>
+ </mj-column>
+ </mj-section>
+ <mj-include path="./partials/_fulfillment_lines" />
+ <mj-include path="../shared/footer" />
+ </mj-container>
+ </mj-body>
+</mjml>