Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add ability to remove voucher from order
Artur Smęt9274577cea41
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 4cfee87842..deb1a6495a 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -3,17 +3,17 @@ from __future__ import unicode_literalsfrom django import formsfrom django.conf import settingsfrom django.shortcuts import get_object_or_404-from django.utils.translation import ugettext_lazy as _from django.utils.translation import pgettext_lazy+from django.utils.translation import ugettext_lazy as _from django_prices.forms import PriceFieldfrom payments import PaymentErrorfrom payments.models import PAYMENT_STATUS_CHOICESfrom satchless.item import InsufficientStockfrom ...cart.forms import QuantityField+from ...order import Statusfrom ...order.models import DeliveryGroup, OrderedItem, OrderNotefrom ...product.models import ProductVariant, Stock-from ...order import Statusclass OrderNoteForm(forms.ModelForm):@@ -211,6 +211,18 @@ class CancelOrderForm(forms.Form):self.order.change_status(status=Status.CANCELLED)+class RemoveVoucherForm(forms.Form):++ def __init__(self, *args, **kwargs):+ self.order = kwargs.pop('order')+ super(RemoveVoucherForm, self).__init__(*args, **kwargs)++ def remove_voucher(self):+ self.order.discount_amount = 0+ self.order.discount_name = ''+ self.order.voucher = None+ self.order.recalculate()+ORDER_STATUS_CHOICES = (('', pgettext_lazy('Order status field value','All')),) + Status.CHOICESdiff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.pyindex 7ee742144a..c4e0d456a3 100644--- a/saleor/dashboard/order/urls.py+++ b/saleor/dashboard/order/urls.py@@ -27,5 +27,7 @@ urlpatterns = [views.orderline_split, name='orderline-split'),url(r'^(?P<order_pk>\d+)/line/(?P<line_pk>\d+)/cancel/$',views.orderline_cancel, name='orderline-cancel'),+ url(r'^(?P<order_pk>\d+)/remove-voucher/$',+ views.remove_order_voucher, name='order-remove-voucher'),url(r'^(?P<order_pk>\d+)/shipment/(?P<group_pk>\d+)/ship/$',views.ship_delivery_group, name='ship-delivery-group')]diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex be72f7404e..e4ed357aa8 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -12,12 +12,12 @@ from prices import Pricefrom ...order.models import Order, OrderedItem, OrderNotefrom ...userprofile.forms import AddressForm-from ..views import (StaffMemberOnlyMixin, FilterByStatusMixin,+from ..views import (FilterByStatusMixin, StaffMemberOnlyMixin,staff_member_required)-from .forms import (OrderNoteForm, MoveItemsForm,- ChangeQuantityForm, ShipGroupForm, CapturePaymentForm,- ReleasePaymentForm, RefundPaymentForm, CancelItemsForm,- CancelOrderForm)+from .forms import (CancelItemsForm, CancelOrderForm, CapturePaymentForm,+ ChangeQuantityForm, MoveItemsForm, OrderNoteForm,+ RefundPaymentForm, ReleasePaymentForm, RemoveVoucherForm,+ ShipGroupForm)class OrderListView(StaffMemberOnlyMixin, FilterByStatusMixin, ListView):@@ -276,3 +276,23 @@ def cancel_order(request, order_pk):ctx = {'order': order}return TemplateResponse(request, 'dashboard/order/modal_cancel_order.html',ctx, status=status)++++def remove_order_voucher(request, order_pk):+ status = 200+ order = get_object_or_404(Order, pk=order_pk)+ form = RemoveVoucherForm(request.POST or None, order=order)+ if form.is_valid():+ msg = _('Removed voucher from Order')+ with transaction.atomic():+ form.remove_voucher()+ order.create_history_entry(comment=msg, user=request.user)+ messages.success(request, 'Voucher removed')+ return redirect('dashboard:order-details', order_pk=order.pk)+ elif form.errors:+ status = 400+ ctx = {'order': order}+ return TemplateResponse(request,+ 'dashboard/order/modal_order_remove_voucher.html',+ ctx, status=status)diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.htmlindex 9a1ff9c3f9..6d8f9a0bb1 100644--- a/saleor/dashboard/templates/dashboard/order/detail.html+++ b/saleor/dashboard/templates/dashboard/order/detail.html@@ -315,7 +315,7 @@<ul id="voucher-actions" class="dropdown-content"><li>- <a href="#base-modal" data-href="#" class="modal-trigger-custom"+ <a href="#base-modal" data-href="{% url 'dashboard:order-remove-voucher' order_pk=order.pk %}" class="modal-trigger-custom"title="{% trans "Remove voucher" %}">{% trans "Remove voucher" %}</a>diff --git a/saleor/dashboard/templates/dashboard/order/modal_order_remove_voucher.html b/saleor/dashboard/templates/dashboard/order/modal_order_remove_voucher.htmlnew file mode 100644index 0000000000..a67b6b7ec6--- /dev/null+++ b/saleor/dashboard/templates/dashboard/order/modal_order_remove_voucher.html@@ -0,0 +1,19 @@+{% load i18n %}+{% load materializecss %}++<div class="modal-content">+ <h5>{% trans "Remove voucher?" %}</h5>+ <p>+ {% blocktrans with order=order%}+ Are you sure, you want remove voucher discount from {{ order }}?+ {% endblocktrans %}</p>+</div>++<div class="modal-footer">+ <form id="release-form" method="post" role="form" class="form-async"+ action="{% url 'dashboard:order-remove-voucher' order_pk=order.pk %}">+ {% csrf_token %}+ <button type="submit" class="modal-action btn-flat red-text">{% trans "Remove voucher" %}</button>+ <a href="#!" aria-hidden="true" class="modal-action modal-close btn-flat blue-text">{% trans "Abort" %}</a>+ </form>+</div>