Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Send order confirmation email after saving draft order
Anna Siwike9bae3fbb54f
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 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_lazyfrom django.utils.translation import npgettext_lazy, pgettext_lazyfrom django_prices.forms import MoneyFieldfrom payments import PaymentError, PaymentStatus-from prices import Money, TaxedMoneyfrom ...account.i18n import (AddressForm as StorefrontAddressForm, PossiblePhoneNumberFormField)@@ -14,7 +13,7 @@ from ...core.exceptions import InsufficientStockfrom ...core.utils import ZERO_TAXED_MONEYfrom ...discount.utils import decrease_voucher_usagefrom ...order import OrderStatus-from ...order.emails import send_note_confirmation+from ...order.emails import send_note_confirmation, send_order_confirmationfrom ...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_addressesclass 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 = Noneself.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.pyindex 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.htmlindex 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 %}