diff --git a/InvenTree/build/templates/build/create_build_item.html b/InvenTree/build/templates/build/create_build_item.html new file mode 100644 index 0000000000..c08b987d36 --- /dev/null +++ b/InvenTree/build/templates/build/create_build_item.html @@ -0,0 +1,9 @@ +{% extends "modal_form.html" %} + +{% block pre_form_content %} +{% if no_stock %} + +{% endif %} +{% endblock %} \ No newline at end of file diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 7cef486d55..6f19c67754 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -355,9 +355,25 @@ class BuildItemCreate(AjaxCreateView): model = BuildItem form_class = forms.EditBuildItemForm - ajax_template_name = 'modal_form.html' + ajax_template_name = 'build/create_build_item.html' ajax_form_title = 'Allocate new Part' + part = None + available_stock = None + + def get_context_data(self): + ctx = super(AjaxCreateView, self).get_context_data() + + if self.part: + ctx['part'] = self.part + + if self.available_stock: + ctx['stock'] = self.available_stock + else: + ctx['no_stock'] = True + + return ctx + def get_form(self): """ Create Form for making / editing new Part object """ @@ -375,7 +391,7 @@ class BuildItemCreate(AjaxCreateView): if part_id: try: - Part.objects.get(pk=part_id) + self.part = Part.objects.get(pk=part_id) query = form.fields['stock_item'].queryset @@ -399,6 +415,8 @@ class BuildItemCreate(AjaxCreateView): form.fields['stock_item'].queryset = query stocks = query.all() + self.available_stock = stocks + # If there is only one item selected, select it if len(stocks) == 1: form.fields['stock_item'].initial = stocks[0].id @@ -408,6 +426,7 @@ class BuildItemCreate(AjaxCreateView): pass except Part.DoesNotExist: + self.part = None pass return form diff --git a/InvenTree/static/script/inventree/build.js b/InvenTree/static/script/inventree/build.js index c982cc254c..e3d1238e5e 100644 --- a/InvenTree/static/script/inventree/build.js +++ b/InvenTree/static/script/inventree/build.js @@ -56,7 +56,7 @@ function loadAllocationTable(table, part_id, part, url, required, button) { launchModalForm(button.attr('url'), { success: function() { table.bootstrapTable('refresh'); - } + }, }); }); diff --git a/InvenTree/templates/modal_form.html b/InvenTree/templates/modal_form.html index 1a99fc09ff..1f5482f8d6 100644 --- a/InvenTree/templates/modal_form.html +++ b/InvenTree/templates/modal_form.html @@ -5,13 +5,13 @@ {% endif %} {% if form.pre_form_warning %} -