diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html
index 3a024c8255..9f504e0901 100644
--- a/InvenTree/build/templates/build/allocate.html
+++ b/InvenTree/build/templates/build/allocate.html
@@ -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 %}
diff --git a/InvenTree/build/templates/build/allocate_view.html b/InvenTree/build/templates/build/allocate_view.html
index 49ee5d71c4..31d35b43f9 100644
--- a/InvenTree/build/templates/build/allocate_view.html
+++ b/InvenTree/build/templates/build/allocate_view.html
@@ -3,6 +3,7 @@
diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py
index da58111dcd..c522208f9e 100644
--- a/InvenTree/order/views.py
+++ b/InvenTree/order/views.py
@@ -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):