Skip to content

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

Move email logic to the form

akjanik86763477919f
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index c5b94ca345..5715af0e37 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -1,15 +1,17 @@
from django import forms
from django.conf import settings
from django.core.validators import MinValueValidator, MaxValueValidator
-from django.urls import reverse_lazy
+from django.urls import reverse_lazy, reverse
from django.utils.translation import npgettext_lazy, pgettext_lazy
from django_prices.forms import PriceField
from payments import PaymentError, PaymentStatus
from satchless.item import InsufficientStock
from ...cart.forms import QuantityField
+from ...core.utils import build_absolute_uri
from ...discount.utils import decrease_voucher_usage
from ...order import GroupStatus
+from ...order.emails import send_note_confirmation
from ...order.models import DeliveryGroup, OrderLine, OrderNote
from ...order.utils import (
add_variant_to_delivery_group, cancel_order, change_order_line_quantity,
@@ -35,8 +37,13 @@ class OrderNoteForm(forms.ModelForm):
'Allow customers to see note toggle',
'Customer can see this note')}
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
+ def send_confirmation_email(self):
+ email = self.instance.order.get_user_current_email()
+ url = build_absolute_uri(
+ reverse(
+ 'order:details', kwargs={'token': self.instance.order.token}))
+ send_note_confirmation.delay(email, url)
+
class ManagePaymentForm(forms.Form):
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 01b2a25f98..3f21e9da05 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -25,7 +25,6 @@ from .utils import (
from ..views import staff_member_required
from ...core.utils import get_paginator_items, build_absolute_uri
from ...order import GroupStatus
-from ...order.emails import send_note_confirmation
from ...order.models import DeliveryGroup, Order, OrderLine, OrderNote
@@ -95,10 +94,7 @@ def order_add_note(request, order_pk):
order.create_history_entry(comment=msg, user=request.user)
messages.success(request, msg)
if note.is_public:
- order_url = build_absolute_uri(
- reverse('order:details', kwargs={'token': order.token}))
- email = order.get_user_current_email()
- send_note_confirmation.delay(email, order_url)
+ form.send_confirmation_email()
elif form.errors:
status = 400
ctx = {'order': order, 'form': form}
diff --git a/saleor/order/forms.py b/saleor/order/forms.py
index a13ead4853..50937b8c52 100644
--- a/saleor/order/forms.py
+++ b/saleor/order/forms.py
@@ -56,8 +56,4 @@ class OrderNoteForm(forms.ModelForm):
widgets = {
'content': forms.Textarea({'rows': 3, 'placeholder': False})}
labels = {
- 'content': pgettext_lazy('Order note', 'Add note to order')
- }
-
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
+ 'content': pgettext_lazy('Order note', 'Add note to order')}
diff --git a/saleor/order/views.py b/saleor/order/views.py
index d8eacc84a7..80775dd3db 100644
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -12,12 +12,8 @@ from django.utils.translation import pgettext_lazy
from payments import PaymentStatus, RedirectNeeded
from . import OrderStatus
-from .emails import send_note_confirmation
from .forms import (
- PaymentDeleteForm,
- PaymentMethodsForm,
- PasswordForm,
- OrderNoteForm)
+ PaymentDeleteForm, PaymentMethodsForm, PasswordForm, OrderNoteForm)
from .models import Order, OrderNote, Payment
from .utils import attach_order_to_user, check_order_status
from ..checkout.forms import NoteForm