Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Confirm draft order modal action
Anna Siwik206007d52595
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex faa6fad861..9ee72a0d29 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -11,8 +11,10 @@ from ...account.i18n import (from ...cart.forms import QuantityFieldfrom ...core.exceptions import InsufficientStockfrom ...discount.utils import decrease_voucher_usage+from ...order import OrderStatusfrom ...order.emails import send_note_confirmation-from ...order.models import Fulfillment, FulfillmentLine, OrderLine, OrderNote+from ...order.models import (+ Fulfillment, FulfillmentLine, Order, OrderLine, OrderNote)from ...order.utils import (add_variant_to_order, cancel_fulfillment, cancel_order,change_order_line_quantity, merge_duplicates_into_order_line,@@ -24,6 +26,28 @@ from ..widgets import PhonePrefixWidgetfrom .utils import fulfill_order_line+class ConfirmDraftOrderForm(forms.ModelForm):+ class Meta:+ model = Order+ fields = []++ def clean(self):+ super().clean()+ if self.instance.status != OrderStatus.DRAFT:+ raise forms.ValidationError(pgettext_lazy(+ 'Confirm draft order form error',+ 'Order must have draft status to confirm'))+ if self.instance.get_total_quantity() == 0:+ raise forms.ValidationError(pgettext_lazy(+ 'Confirm draft order form error',+ 'Could not confirm order without any products'))+ return self.cleaned_data++ def save(self, commit=True):+ self.instance.status = OrderStatus.UNFULFILLED+ return super().save(commit)++class OrderNoteForm(forms.ModelForm):class Meta:model = OrderNotediff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.pyindex 79dfe85568..11cbe0418d 100644--- a/saleor/dashboard/order/urls.py+++ b/saleor/dashboard/order/urls.py@@ -5,6 +5,8 @@ from . import viewsurlpatterns = [url(r'^$', views.order_list, name='orders'),url(r'^add/$', views.order_create, name='order-create'),+ url(r'^(?P<order_pk>\d+)/confirm-draft/$',+ views.confirm_draft_order, name='draft-order-confirm'),url(r'^(?P<order_pk>\d+)/$',views.order_details, name='order-details'),url(r'^(?P<order_pk>\d+)/add-note/$',diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex 12c388240a..a602769429 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -27,9 +27,10 @@ from .filters import OrderFilterfrom .forms import (AddressForm, AddVariantToOrderForm, BaseFulfillmentLineFormSet,CancelFulfillmentForm, CancelOrderForm, CancelOrderLineForm,- CapturePaymentForm, ChangeQuantityForm, ChangeStockForm, FulfillmentForm,- FulfillmentLineForm, FulfillmentTrackingNumberForm, OrderNoteForm,- RefundPaymentForm, ReleasePaymentForm, RemoveVoucherForm)+ CapturePaymentForm, ChangeQuantityForm, ChangeStockForm,+ ConfirmDraftOrderForm, FulfillmentForm, FulfillmentLineForm,+ FulfillmentTrackingNumberForm, OrderNoteForm, RefundPaymentForm,+ ReleasePaymentForm, RemoveVoucherForm)from .utils import (create_invoice_pdf, create_packing_slip_pdf, get_statics_absolute_url)@@ -61,6 +62,27 @@ def order_create(request):return redirect('dashboard:order-details', order_pk=order.pk)+@staff_member_required+@permission_required('order.edit_order')+def confirm_draft_order(request, order_pk):+ order = get_object_or_404(Order, pk=order_pk, status=OrderStatus.DRAFT)+ status = 200+ form = ConfirmDraftOrderForm(request.POST or None, instance=order)+ if form.is_valid():+ form.save()+ msg = pgettext_lazy(+ 'Dashboard message related to an order',+ 'Draft order confirmed')+ order.history.create(content=msg, user=request.user)+ messages.success(request, msg)+ return redirect('dashboard:order-details', order_pk=order.pk)+ elif form.errors:+ status = 400+ template = 'dashboard/order/modal/confirm_order.html'+ ctx = {'form': form, 'order': order}+ return TemplateResponse(request, template, ctx, status=status)++@staff_member_required@permission_required('order.view_order')def order_details(request, order_pk):diff --git a/saleor/order/models.py b/saleor/order/models.pyindex e47ed62b68..b06cc76ede 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -144,7 +144,7 @@ class Order(models.Model):return sum([line.quantity for line in self])def can_edit(self):- return self.status == OrderStatus.UNFULFILLED+ return self.status == OrderStatus.DRAFTdef can_fulfill(self):statuses = {OrderStatus.UNFULFILLED, OrderStatus.PARTIALLY_FULFILLED}diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex a337423340..dd19bec9a6 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -359,6 +359,9 @@<a href="#base-modal" data-href="{% url 'dashboard:add-variant-to-order' order_pk=order.pk %}" class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Add product to order" context "Order summary card action title" %}">{% trans "Add product" context "Order summary card action" %}</a>+ <a href="#base-modal" data-href="{% url 'dashboard:draft-order-confirm' order_pk=order.pk %}" class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Confirm order" context "Order summary card action title" %}">+ {% trans "Confirm" context "Order summary card action" %}+ </a>{% endif %}</div>{% endif %}diff --git a/templates/dashboard/order/modal/confirm_order.html b/templates/dashboard/order/modal/confirm_order.htmlnew file mode 100644index 0000000000..51b93a60b0--- /dev/null+++ b/templates/dashboard/order/modal/confirm_order.html@@ -0,0 +1,24 @@+{% extends "dashboard/base_modal.html" %}++{% load i18n %}+{% load materializecss %}++{% block action_url %}+{% url 'dashboard:draft-order-confirm' order_pk=order.pk %}+{% endblock %}++{% block title %}+{% trans "Confirm order" context "Modal confirm order title" %}+{% endblock %}++{% block content %}+ <div class="col s12">+ {% 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 %}+ </div>+{% endblock %}++{% block primary_action %}+{% trans "Confirm" context "Modal confirm order primary action" %}+{% endblock %}