Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove shipping from order action
Anna Siwikf4e3e2b5916e
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex a713bf0964..371f5a6aae 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -121,7 +121,7 @@ class OrderCustomerForm(forms.ModelForm):super().__init__(*args, **kwargs)if self.instance.user:self.fields['user'].set_initial(- self.instane.user, label=self.instance.user.label)+ self.instance.user, label=self.instance.user.label)def clean(self):cleaned_data = super().clean()@@ -144,8 +144,7 @@ class OrderShippingForm(forms.ModelForm):"""Set shipping name and shipping price in an order."""shipping_method = AjaxSelect2ChoiceField(- queryset=ShippingMethodCountry.objects.all(),- required=False, min_input=0)+ queryset=ShippingMethodCountry.objects.all(), min_input=0)class Meta:model = Order@@ -174,12 +173,24 @@ class OrderShippingForm(forms.ModelForm):def save(self, commit=True):method = self.instance.shipping_method- if method:- self.instance.shipping_method_name = method.shipping_method.name- self.instance.shipping_price = method.get_total_price()- else:- self.instance.shipping_method_name = None- self.instance.shipping_price = ZERO_TAXED_MONEY+ self.instance.shipping_method_name = method.shipping_method.name+ self.instance.shipping_price = method.get_total_price()+ recalculate_order(self.instance)+ return super().save(commit)+++class OrderRemoveShippingForm(forms.ModelForm):+ """Remove shipping name and shipping price from an order."""++ class Meta:+ model = Order+ fields = []++ def save(self, commit=True):+ self.instance.shipping_method = None+ self.instance.shipping_method_name = None+ self.instance.shipping_price = ZERO_TAXED_MONEY+ recalculate_order(self.instance)return super().save(commit)diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.pyindex 8e7b48fcd9..57ad010da3 100644--- a/saleor/dashboard/order/urls.py+++ b/saleor/dashboard/order/urls.py@@ -19,6 +19,8 @@ urlpatterns = [views.order_customer_edit, name='order-customer-edit'),url(r'^(?P<order_pk>\d+)/shipping/edit/$',views.order_shipping_edit, name='order-shipping-edit'),+ url(r'^(?P<order_pk>\d+)/shipping/remove/$',+ views.order_shipping_remove, name='order-shipping-remove'),url(r'^(?P<order_pk>\d+)/delete/$',views.remove_draft_order, name='draft-order-delete'),diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex aae508a917..18b11192a5 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -31,8 +31,8 @@ from .forms import (CapturePaymentForm, ChangeQuantityForm, ChangeStockForm,ConfirmDraftOrderForm, FulfillmentForm, FulfillmentLineForm,FulfillmentTrackingNumberForm, OrderCustomerForm, OrderNoteForm,- OrderShippingForm, RefundPaymentForm, ReleasePaymentForm,- RemoveVoucherForm)+ OrderRemoveShippingForm, OrderShippingForm, RefundPaymentForm,+ ReleasePaymentForm, RemoveVoucherForm)from .utils import (create_invoice_pdf, create_packing_slip_pdf, get_statics_absolute_url)@@ -388,6 +388,25 @@ def order_shipping_edit(request, order_pk):status=status)+@staff_member_required+@permission_required('order.edit_order')+def order_shipping_remove(request, order_pk):+ order = get_object_or_404(Order, pk=order_pk, status=OrderStatus.DRAFT)+ form = OrderRemoveShippingForm(request.POST or None, instance=order)+ status = 200+ if form.is_valid():+ form.save()+ msg = pgettext_lazy('Dashboard message', 'Shipping removed')+ messages.success(request, msg)+ return redirect('dashboard:order-details', order_pk=order_pk)+ elif form.errors:+ status = 400+ ctx = {'order': order, 'form': form}+ return TemplateResponse(+ request, 'dashboard/order/modal/remove_shipping.html', ctx,+ status=status)++@staff_member_required@permission_required('order.edit_order')def cancel_order(request, order_pk):diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex ad6a14c1d9..2bddca0a3f 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -353,6 +353,14 @@{% trans "Edit shipping" context "Order totals action" %}</a></li>+ {% if order.shipping_method %}+ <li>+ <a href="#base-modal" data-href="{% url 'dashboard:order-shipping-remove' order_pk=order.pk %}"+ class="modal-trigger-custom" title="{% trans "Remove shipping" context "Order totals action" %}">+ {% trans "Remove shipping" context "Order totals action" %}+ </a>+ </li>+ {% endif %}</ul>{% else %}{% if order.shipping_method_name %}diff --git a/templates/dashboard/order/modal/remove_shipping.html b/templates/dashboard/order/modal/remove_shipping.htmlnew file mode 100644index 0000000000..0ba441c590--- /dev/null+++ b/templates/dashboard/order/modal/remove_shipping.html@@ -0,0 +1,26 @@+{% extends "dashboard/base_modal.html" %}++{% load i18n %}+{% load materializecss %}++{% block action_url %}+{% url 'dashboard:order-shipping-remove' order_pk=order.pk %}+{% endblock %}++{% block title %}+{% trans "Remove shipping from order" context "Modal remove shipping from order title" %}+{% endblock %}++{% block content %}+ <div class="col s12">+ {% trans "Are you sure you want remove shipping from order from an order?" context "Modal remove shipping from order text" %}+ </div>+{% endblock %}++{% block cancel_action %}+{% trans "Abort" context "Modal remove shipping from order cancel action" %}+{% endblock %}++{% block primary_action %}+{% trans "Remove shipping" context "Modal remove shipping from order primary action" %}+{% endblock %}diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.pyindex 78b6ad9806..e3f3a3a94d 100644--- a/tests/dashboard/test_order.py+++ b/tests/dashboard/test_order.py@@ -1100,10 +1100,10 @@ def test_view_order_shipping_edit_not_draft_order(@pytest.mark.django_db-def test_view_order_shipping_edit_remove_shipping(admin_client, draft_order):+def test_view_order_shipping_remove(admin_client, draft_order):url = reverse(- 'dashboard:order-shipping-edit', kwargs={'order_pk': draft_order.pk})- data = {'shipping_method': ''}+ 'dashboard:order-shipping-remove', kwargs={'order_pk': draft_order.pk})+ data = {'csrfmiddlewaretoken': 'hello'}response = admin_client.post(url, data)