Skip to content

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

Send order confirmation email after saving draft order

Anna Siwike9bae3fbb54f
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 66f31cfc0e..c4750004ac 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -5,7 +5,6 @@ from django.urls import reverse, reverse_lazy
from django.utils.translation import npgettext_lazy, pgettext_lazy
from django_prices.forms import MoneyField
from payments import PaymentError, PaymentStatus
-from prices import Money, TaxedMoney
from ...account.i18n import (
AddressForm as StorefrontAddressForm, PossiblePhoneNumberFormField)
@@ -14,7 +13,7 @@ from ...core.exceptions import InsufficientStock
from ...core.utils import ZERO_TAXED_MONEY
from ...discount.utils import decrease_voucher_usage
from ...order import OrderStatus
-from ...order.emails import send_note_confirmation
+from ...order.emails import send_note_confirmation, send_order_confirmation
from ...order.models import (
Fulfillment, FulfillmentLine, Order, OrderLine, OrderNote)
from ...order.utils import (
@@ -31,6 +30,11 @@ from .utils import fulfill_order_line, update_order_with_user_addresses
class ConfirmDraftOrderForm(forms.ModelForm):
"""Save draft order as a ready to fulfill."""
+ notify_customer = forms.BooleanField(
+ label=pgettext_lazy(
+ 'Send email to customer about order created by staff users',
+ 'Notify customer'),
+ required=False, initial=True)
class Meta:
model = Order
@@ -80,6 +84,10 @@ class ConfirmDraftOrderForm(forms.ModelForm):
self.instance.shipping_address.delete()
self.instance.shipping_method_name = None
self.instance.shipping_price = ZERO_TAXED_MONEY
+ if self.cleaned_data.get('notify_customer'):
+ email = self.instance.get_user_current_email()
+ if email:
+ send_order_confirmation.delay(self.instance.pk)
return super().save(commit)
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 574af0bf28..11cc346727 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -59,7 +59,6 @@ def order_create(request):
msg = pgettext_lazy(
'Dashboard message related to an order',
'Draft order created')
- order.history.create(content=msg, user=request.user)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
@@ -74,7 +73,7 @@ def confirm_draft_order(request, order_pk):
form.save()
msg = pgettext_lazy(
'Dashboard message related to an order',
- 'Draft order confirmed')
+ 'Order created from draft order')
order.history.create(content=msg, user=request.user)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
diff --git a/templates/dashboard/order/modal/confirm_order.html b/templates/dashboard/order/modal/confirm_order.html
index 51b93a60b0..25ee79b76e 100644
--- a/templates/dashboard/order/modal/confirm_order.html
+++ b/templates/dashboard/order/modal/confirm_order.html
@@ -16,6 +16,7 @@
{% blocktrans trimmed with order=order context "Modal confirm order text" %}
Are you sure you want confirm order {{ order }}? Once the order has been confirmed, you will not be able to make changes.
{% endblocktrans %}
+ {{ form.notify_customer|materializecss }}
</div>
{% endblock %}