diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 4844ef4344..8432d9a6ef 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -8,8 +8,11 @@ from __future__ import unicode_literals from django import forms from django.utils.translation import ugettext as _ +from mptt.fields import TreeNodeChoiceField + from InvenTree.forms import HelperForm +from stock.models import StockLocation from .models import PurchaseOrder, PurchaseOrderLineItem @@ -35,6 +38,17 @@ class CancelPurchaseOrderForm(HelperForm): ] +class ReceivePurchaseOrderForm(HelperForm): + + location = TreeNodeChoiceField(queryset=StockLocation.objects.all(), required=True, help_text=_('Receive parts to this location')) + + class Meta: + model = PurchaseOrder + fields = [ + 'location', + ] + + class EditPurchaseOrderForm(HelperForm): """ Form for editing a PurchaseOrder object """ diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index 83bd526a96..a3a92e8612 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -190,6 +190,14 @@ $("#cancel-order").click(function() { $("#receive-order").click(function() { launchModalForm("{% url 'purchase-order-receive' order.id %}", { reload: true, + secondary: [ + { + field: 'location', + label: 'New Location', + title: 'Create new stock location', + url: "{% url 'stock-location-create' %}", + }, + ] }); }); diff --git a/InvenTree/order/templates/order/receive_parts.html b/InvenTree/order/templates/order/receive_parts.html index 9f773cd411..3ebaa66889 100644 --- a/InvenTree/order/templates/order/receive_parts.html +++ b/InvenTree/order/templates/order/receive_parts.html @@ -8,23 +8,6 @@ Receive outstanding parts for {{ order }} - {{ order.description }} - -
- - {% if not destination %} - Select location to receive parts - {% else %} -

Location of received parts

- {% endif %} -
- -

Select parts to receive against this order.

@@ -64,6 +47,8 @@ Receive outstanding parts for {{ order }} - {{ order.description }} {% endfor %} + + {% crispy form %} {% endblock %} \ No newline at end of file diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 49d2ed01ed..d2300f2527 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -206,7 +206,7 @@ class PurchaseOrderExport(AjaxView): return DownloadFile(filedata, filename) -class PurchaseOrderReceive(AjaxView): +class PurchaseOrderReceive(AjaxUpdateView): """ View for receiving parts which are outstanding against a PurchaseOrder. Any parts which are outstanding are listed. @@ -214,6 +214,7 @@ class PurchaseOrderReceive(AjaxView): """ + form_class = order_forms.ReceivePurchaseOrderForm ajax_form_title = "Receive Parts" ajax_template_name = "order/receive_parts.html" @@ -225,8 +226,6 @@ class PurchaseOrderReceive(AjaxView): ctx = { 'order': self.order, 'lines': self.lines, - 'locations': StockLocation.objects.all(), - 'destination': self.destination, } return ctx @@ -245,7 +244,7 @@ class PurchaseOrderReceive(AjaxView): # Pre-fill the remaining quantity line.receive_quantity = line.remaining() - return self.renderJsonResponse(request) + return self.renderJsonResponse(request, form=self.get_form()) def post(self, request, *args, **kwargs): """ Respond to a POST request. Data checking and error handling. @@ -260,8 +259,8 @@ class PurchaseOrderReceive(AjaxView): self.destination = None # Extract the destination for received parts - if 'receive_location' in request.POST: - pk = request.POST['receive_location'] + if 'location' in request.POST: + pk = request.POST['location'] try: self.destination = StockLocation.objects.get(id=pk) except (StockLocation.DoesNotExist, ValueError): @@ -316,7 +315,7 @@ class PurchaseOrderReceive(AjaxView): 'success': 'Items marked as received', } - return self.renderJsonResponse(request, data=data) + return self.renderJsonResponse(request, data=data, form=self.get_form()) @transaction.atomic def receive_parts(self):