This commit is contained in:
Oliver Walters 2020-11-03 20:37:33 +11:00
parent 2b91f69c7d
commit ac03dab8de
5 changed files with 36 additions and 35 deletions

View File

@ -740,14 +740,7 @@ class Build(MPTTModel):
parts = [] parts = []
for item in self.part.bom_items.all().prefetch_related('sub_part'): for item in self.part.bom_items.all().prefetch_related('sub_part'):
part = { parts.append(item.sub_part)
'part': item.sub_part,
'per_build': item.quantity,
'quantity': item.quantity * self.quantity,
'allocated': self.getAllocatedQuantity(item.sub_part)
}
parts.append(part)
return parts return parts

View File

@ -24,9 +24,11 @@ InvenTree | Allocate Parts
<button class='btn btn-primary' type='button' id='btn-create-output' title='{% trans "Create new build output" %}'> <button class='btn btn-primary' type='button' id='btn-create-output' title='{% trans "Create new build output" %}'>
<span class='fas fa-plus-circle'></span> {% trans "Create New Output" %} <span class='fas fa-plus-circle'></span> {% trans "Create New Output" %}
</button> </button>
<button class='btn btn-primary' type='button' id='btn-order-parts' title='{% trans "Order required parts" %}'> <!--
<span class='fas fa-shopping-cart'></span> {% trans "Order Parts" %} <button class='btn btn-primary' type='button' id='btn-order-parts' title='{% trans "Order required parts" %}'>
</button> <span class='fas fa-shopping-cart'></span> {% trans "Order Parts" %}
</button>
-->
<button class='btn btn-danger' type='button' id='btn-unallocate' title='{% trans "Unallocate stock" %}'> <button class='btn btn-danger' type='button' id='btn-unallocate' title='{% trans "Unallocate stock" %}'>
<span class='fas fa-minus-circle'></span> {% trans "Unallocate Stock" %} <span class='fas fa-minus-circle'></span> {% trans "Unallocate Stock" %}
</button> </button>
@ -86,7 +88,7 @@ InvenTree | Allocate Parts
launchModalForm( launchModalForm(
"{% url 'build-unallocate' build.id %}", "{% url 'build-unallocate' build.id %}",
{ {
success: reloadTable, reload: true,
} }
); );
}); });

View File

@ -286,38 +286,43 @@ class BuildOutputDelete(AjaxUpdateView):
return initials return initials
def post(self, request, *args, **kwargs): def validate(self, build, form, **kwargs):
build = self.get_object() data = form.cleaned_data
form = self.get_form()
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: try:
output = StockItem.objects.get(pk=output_id) output = StockItem.objects.get(pk=output_id)
except (ValueError, StockItem.DoesNotExist): except (ValueError, StockItem.DoesNotExist):
output = None pass
valid = False if output:
if not output.build == build:
if confirm: form.add_error(None, _('Build output does not match build'))
if output:
build.deleteBuildOutput(output)
valid = True
else:
form.add_error(None, _('Build or output not specified'))
else: else:
form.add_error('confirm', _('Confirm unallocation of build stock')) form.add_error(None, _('Build output must be specified'))
form.add_error(None, _('Check the confirmation box'))
data = { def save(self, build, form, **kwargs):
'form_valid': valid,
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): class BuildUnallocate(AjaxUpdateView):
""" View to un-allocate all parts from a build. """ View to un-allocate all parts from a build.

View File

@ -910,9 +910,10 @@ class OrderParts(AjaxView):
try: try:
build = Build.objects.get(id=build_id) build = Build.objects.get(id=build_id)
parts = build.part.required_parts() parts = build.required_parts
for part in parts: for part in parts:
# If ordering from a Build page, ignore parts that we have enough of # If ordering from a Build page, ignore parts that we have enough of
if part.quantity_to_order <= 0: if part.quantity_to_order <= 0:
continue continue

View File

@ -658,14 +658,14 @@ function loadBuildTable(table, options) {
}, },
{ {
field: 'quantity', field: 'quantity',
title: '{% trans "Quantity" %}', title: '{% trans "Completed" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
return makeProgressBar( return makeProgressBar(
row.completed, row.completed,
row.quantity, row.quantity,
{ {
style: 'max', //style: 'max',
} }
); );
} }