-
+
{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/order/templates/order/order_wizard/select_pos.html b/InvenTree/order/templates/order/order_wizard/select_pos.html
new file mode 100644
index 0000000000..140527f72e
--- /dev/null
+++ b/InvenTree/order/templates/order/order_wizard/select_pos.html
@@ -0,0 +1,49 @@
+{% extends "modal_form.html" %}
+
+{% block form %}
+
+
+ Step 2 of 2 - Select Purchase Orders
+
+
+
+ Select existing purchase orders, or create new orders.
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py
index bf2561233d..68273f7410 100644
--- a/InvenTree/order/views.py
+++ b/InvenTree/order/views.py
@@ -155,15 +155,41 @@ class OrderParts(AjaxView):
# List of Parts we wish to order
parts = []
+ suppliers = []
def get_context_data(self):
ctx = {}
ctx['parts'] = sorted(self.parts, key=lambda part: int(part.order_quantity), reverse=True)
+ ctx['suppliers'] = self.suppliers
return ctx
+ def get_suppliers(self):
+ """ Calculates a list of suppliers which the user will need to create POs for.
+ This is calculated AFTER the user finishes selecting the parts to order.
+ Crucially, get_parts() must be called before get_suppliers()
+ """
+
+ suppliers = {}
+
+ for part in self.parts:
+ supplier_part_id = part.order_supplier
+
+ try:
+ supplier = SupplierPart.objects.get(pk=supplier_part_id).supplier
+ except SupplierPart.DoesNotExist:
+ continue
+
+ if not supplier.name in suppliers:
+ supplier.order_items = []
+ suppliers[supplier.name] = supplier
+
+ suppliers[supplier.name].order_items.append(part)
+
+ self.suppliers = [suppliers[key] for key in suppliers.keys()]
+
def get_parts(self):
""" Determine which parts the user wishes to order.
This is performed on the initial GET request.
@@ -279,6 +305,9 @@ class OrderParts(AjaxView):
self.parts = []
+ # Any errors for the part selection form?
+ errors = False
+
for item in self.request.POST:
if item.startswith('supplier-'):
@@ -316,12 +345,18 @@ class OrderParts(AjaxView):
self.parts.append(part)
- print(part.name, part.order_supplier, part.order_quantity)
+ if supplier_part is None:
+ errors = True
data = {
'form_valid': False,
}
+ # No errors? Proceed to PO selection form
+ if errors == False:
+ self.ajax_template_name = 'order/order_wizard/select_pos.html'
+ self.get_suppliers()
+
return self.renderJsonResponse(self.request, data=data)