Order parts directly from a build

This commit is contained in:
Oliver Walters 2019-06-12 00:21:18 +10:00
parent 74327d3094
commit b138a4bd5f
3 changed files with 24 additions and 1 deletions

View File

@ -68,6 +68,14 @@ InvenTree | Allocate Parts
location.href = "{% url 'build-allocate' build.id %}?edit=1";
});
$("#btn-order-parts").click(function() {
launchModalForm("/order/purchase-order/order-parts/", {
data: {
build: {{ build.id }},
},
});
});
{% endif %}
{% endblock %}

View File

@ -3,6 +3,7 @@
<div id='#build-item-toolbar'>
<div class='btn-group'>
<button class='btn btn-primary' type='button' id='btn-allocate' title='Allocate Stock'>Allocate</button>
<button class='btn btn-primary' type='button' id='btn-order-parts' title='Order Parts'>Order Parts</button>
</div>
</div>

View File

@ -11,6 +11,7 @@ from django.views.generic.edit import FormMixin
from django.forms import HiddenInput
from .models import PurchaseOrder, PurchaseOrderLineItem
from build.models import Build
from company.models import Company, SupplierPart
from stock.models import StockItem
from part.models import Part
@ -211,6 +212,19 @@ class OrderParts(AjaxView):
for part in parts:
part_ids.add(part.id)
# User has provided a Build ID
elif 'build' in self.request.GET:
build_id = self.request.GET.get('build')
try:
build = Build.objects.get(id=build_id)
parts = build.part.required_parts()
for part in parts:
part_ids.add(part.id)
except Build.DoesNotExist:
pass
# Create the list of parts
for id in part_ids:
try:
@ -220,7 +234,7 @@ class OrderParts(AjaxView):
self.parts.append(part)
return self.parts
return sorted(self.parts, key=lambda part: part.quantity_to_order, reverse=True)
def get(self, request, *args, **kwargs):