Skip to content

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

Create fulfillment in modal

Anna Siwik3c07a30a7eda
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 98e4045474..199f2fa1ea 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -12,7 +12,7 @@ from ...cart.forms import QuantityField
from ...core.exceptions import InsufficientStock
from ...discount.utils import decrease_voucher_usage
from ...order.emails import send_note_confirmation
-from ...order.models import OrderLine, OrderNote
+from ...order.models import Fulfillment, OrderLine, OrderNote
from ...order.utils import (
add_variant_to_order, cancel_order, change_order_line_quantity,
merge_duplicates_into_order_line, recalculate_order)
@@ -311,3 +311,14 @@ class AddVariantToOrderForm(forms.Form):
class AddressForm(StorefrontAddressForm):
phone = PossiblePhoneNumberFormField(
widget=PhonePrefixWidget, required=False)
+
+
+class FulfillmentForm(forms.ModelForm):
+ class Meta:
+ model = Fulfillment
+ fields = ['tracking_number']
+
+ def __init__(self, *args, **kwargs):
+ order = kwargs.pop('order')
+ super().__init__(*args, **kwargs)
+ self.instance.order = order
diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.py
index c36d25624c..36a7d1f703 100644
--- a/saleor/dashboard/order/urls.py
+++ b/saleor/dashboard/order/urls.py
@@ -30,6 +30,8 @@ urlpatterns = [
views.remove_order_voucher, name='order-remove-voucher'),
url(r'^(?P<order_pk>\d+)/add-variant/$',
views.add_variant_to_order, name='add-variant-to-order'),
+ url(r'^(?P<order_pk>\d+)/fulfill/$',
+ views.fulfill_order_lines, name='fulfill-order-lines'),
url(r'^(?P<order_pk>\d+)/invoice/$',
views.order_invoice, name='order-invoice'),
url(r'^(?P<order_pk>\d+)/packing-slips/$',
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 9e6f3bc4e6..34fa0e4060 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -14,14 +14,14 @@ from prices import Money, TaxedMoney
from ...core.exceptions import InsufficientStock
from ...core.utils import ZERO_TAXED_MONEY, get_paginator_items
from ...order import OrderStatus
-from ...order.models import Order, OrderLine, OrderNote
+from ...order.models import Fulfillment, Order, OrderLine, OrderNote
from ...product.models import StockLocation
from ..views import staff_member_required
from .filters import OrderFilter
from .forms import (
AddressForm, AddVariantToOrderForm, CancelOrderForm, CancelOrderLineForm,
- CapturePaymentForm, ChangeQuantityForm, ChangeStockForm, OrderNoteForm,
- RefundPaymentForm, ReleasePaymentForm, RemoveVoucherForm)
+ CapturePaymentForm, ChangeQuantityForm, ChangeStockForm, FulfillmentForm,
+ OrderNoteForm, RefundPaymentForm, ReleasePaymentForm, RemoveVoucherForm)
from .utils import (
create_invoice_pdf, create_packing_slip_pdf, get_statics_absolute_url)
@@ -364,3 +364,20 @@ def orderline_change_stock(request, order_pk, line_pk):
ctx = {'order_pk': order_pk, 'line_pk': line_pk, 'form': form}
template = 'dashboard/order/modal/order_line_stock.html'
return TemplateResponse(request, template, ctx, status=status)
+
+
+@staff_member_required
+@permission_required('order.edit_order')
+def fulfill_order_lines(request, order_pk):
+ qs = Order.objects.prefetch_related('lines')
+ order = get_object_or_404(qs, pk=order_pk)
+ status = 200
+ form = FulfillmentForm(
+ request.POST or None, order=order, instance=Fulfillment())
+ if form.is_valid():
+ fulfillment = form.save()
+ elif form.errors:
+ status = 400
+ ctx = {'form': form, 'order': order}
+ template = 'dashboard/order/modal/fulfill_order_lines.html'
+ return TemplateResponse(request, template, ctx, status=status)
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index 145e7df5f4..c75062f0f9 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -330,6 +330,9 @@
</div>
{% if perms.order.edit_order and order.is_open %}
<div class="data-table-action">
+ <a href="#base-modal" data-href="{% url 'dashboard:fulfill-order-lines' order_pk=order.pk %}" class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Fulfill order" context "Order summary card action title" %}">
+ {% trans "Fulfill" context "Order summary card action" %}
+ </a>
<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>
diff --git a/templates/dashboard/order/modal/fulfill_order_lines.html b/templates/dashboard/order/modal/fulfill_order_lines.html
new file mode 100644
index 0000000000..7a9bf7cbff
--- /dev/null
+++ b/templates/dashboard/order/modal/fulfill_order_lines.html
@@ -0,0 +1,21 @@
+{% extends "dashboard/base_modal.html" %}
+
+{% load i18n %}
+{% load materializecss %}
+{% load dashboard %}
+
+{% block action_url %}
+{% url 'dashboard:fulfill-order-lines' order_pk=order.pk %}
+{% endblock %}
+
+{% block title %}
+{% trans "Fulfill order" context "Modal fulfill order title" %}
+{% endblock %}
+
+{% block content %}
+ {{ form }}
+{% endblock %}
+
+{% block primary_action %}
+{% trans "Fulfill" context "Modal fulfill order primary action" %}
+{% endblock %}