diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 1e4239e974..1eb958b457 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -740,14 +740,7 @@ class Build(MPTTModel): parts = [] for item in self.part.bom_items.all().prefetch_related('sub_part'): - part = { - 'part': item.sub_part, - 'per_build': item.quantity, - 'quantity': item.quantity * self.quantity, - 'allocated': self.getAllocatedQuantity(item.sub_part) - } - - parts.append(part) + parts.append(item.sub_part) return parts diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html index 29903c0b70..e811c37ce8 100644 --- a/InvenTree/build/templates/build/allocate.html +++ b/InvenTree/build/templates/build/allocate.html @@ -24,9 +24,11 @@ InvenTree | Allocate Parts - + @@ -86,7 +88,7 @@ InvenTree | Allocate Parts launchModalForm( "{% url 'build-unallocate' build.id %}", { - success: reloadTable, + reload: true, } ); }); diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index f40a5a3480..197ee72e9c 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -286,38 +286,43 @@ class BuildOutputDelete(AjaxUpdateView): return initials - def post(self, request, *args, **kwargs): + def validate(self, build, form, **kwargs): - build = self.get_object() - form = self.get_form() + data = form.cleaned_data - confirm = request.POST.get('confirm', False) + confirm = data.get('confirm', False) - output_id = request.POST.get('output_id', None) + if not confirm: + form.add_error('confirm', _('Confirm unallocation of build stock')) + form.add_error(None, _('Check the confirmation box')) + + output_id = data.get('output_id', None) + output = None try: output = StockItem.objects.get(pk=output_id) except (ValueError, StockItem.DoesNotExist): - output = None + pass - valid = False - - if confirm: - if output: - build.deleteBuildOutput(output) - valid = True - else: - form.add_error(None, _('Build or output not specified')) + if output: + if not output.build == build: + form.add_error(None, _('Build output does not match build')) else: - form.add_error('confirm', _('Confirm unallocation of build stock')) - form.add_error(None, _('Check the confirmation box')) + form.add_error(None, _('Build output must be specified')) - data = { - 'form_valid': valid, + def save(self, build, form, **kwargs): + + output_id = form.cleaned_data.get('output_id') + + output = StockItem.objects.get(pk=output_id) + + build.deleteBuildOutput(output) + + def get_data(self): + return { + 'danger': _('Build output deleted'), } - return self.renderJsonResponse(request, form, data) - class BuildUnallocate(AjaxUpdateView): """ View to un-allocate all parts from a build. diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index d0e838a08b..a65cc300fa 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -910,9 +910,10 @@ class OrderParts(AjaxView): try: build = Build.objects.get(id=build_id) - parts = build.part.required_parts() + parts = build.required_parts for part in parts: + # If ordering from a Build page, ignore parts that we have enough of if part.quantity_to_order <= 0: continue diff --git a/InvenTree/templates/js/build.js b/InvenTree/templates/js/build.js index d46f9df679..ab6f0e4e0a 100644 --- a/InvenTree/templates/js/build.js +++ b/InvenTree/templates/js/build.js @@ -658,14 +658,14 @@ function loadBuildTable(table, options) { }, { field: 'quantity', - title: '{% trans "Quantity" %}', + title: '{% trans "Completed" %}', sortable: true, formatter: function(value, row, index, field) { return makeProgressBar( row.completed, row.quantity, { - style: 'max', + //style: 'max', } ); }