Update ReceivePurchaseOrder form

- Location field is now a proper MPTT field
- Ability to create a new location
This commit is contained in:
Oliver Walters 2019-09-23 19:02:36 +10:00
parent 2a31820abe
commit 21e369e6cc
4 changed files with 30 additions and 24 deletions

View File

@ -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 """

View File

@ -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' %}",
},
]
});
});

View File

@ -8,23 +8,6 @@ Receive outstanding parts for <b>{{ order }}</b> - <i>{{ order.description }}</i
{% csrf_token %}
{% load crispy_forms_tags %}
<div class='control-group'>
<label class='control-label requiredField'>Location</label>
<div class='controls'>
<select class='select' name='receive_location'>
<option value=''>---------</option>
{% for loc in locations %}
<option value='{{ loc.id }}' {% if destination.id == loc.id %}selected='selected'{% endif %}>{{ loc.pathstring }} - {{ loc.description }}</option>
{% endfor %}
</select>
{% if not destination %}
<span class='help-inline'>Select location to receive parts</span>
{% else %}
<p class='help-block'>Location of received parts</p>
{% endif %}
</div>
</div>
<label class='control-label'>Parts</label>
<p class='help-block'>Select parts to receive against this order.</p>
@ -64,6 +47,8 @@ Receive outstanding parts for <b>{{ order }}</b> - <i>{{ order.description }}</i
</tr>
{% endfor %}
</table>
{% crispy form %}
</form>
{% endblock %}

View File

@ -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):