Added some more buttons, etc

This commit is contained in:
Oliver Walters 2020-10-26 22:34:40 +11:00
parent 5e0d1fe25a
commit b38fde85f2
7 changed files with 78 additions and 34 deletions

View File

@ -90,18 +90,26 @@ class UnallocateBuildForm(HelperForm):
model = Build
fields = [
'confirm',
'output_id',
'part_id',
]
class ConfirmBuildForm(HelperForm):
class AutoAllocateForm(HelperForm):
""" Form for auto-allocation of stock to a build """
confirm = forms.BooleanField(required=False, help_text=_('Confirm'))
output_id = forms.IntegerField(
required=False,
widget=forms.HiddenInput()
)
class Meta:
model = Build
fields = [
'confirm'
'confirm',
'output_id',
]

View File

@ -306,7 +306,7 @@ class Build(MPTTModel):
self.status = BuildStatus.CANCELLED
self.save()
def getAutoAllocations(self):
def getAutoAllocations(self, output):
""" Return a list of parts which will be allocated
using the 'AutoAllocate' function.
@ -316,12 +316,18 @@ class Build(MPTTModel):
- Take as many parts as available (up to the quantity required for the BOM)
- If there are multiple StockItems available, ignore (leave up to the user)
Args:
output: A stock item (build output) to auto-allocate against
Returns:
A list object containing the StockItem objects to be allocated (and the quantities)
"""
allocations = []
"""
Iterate through each item in the BOM
"""
for item in self.part.bom_items.all().prefetch_related('sub_part'):
# How many parts required for this build?
@ -409,8 +415,12 @@ class Build(MPTTModel):
output.delete()
@transaction.atomic
def autoAllocate(self):
""" Run auto-allocation routine to allocate StockItems to this Build.
def auto_allocate(self, output=None):
"""
Run auto-allocation routine to allocate StockItems to this Build.
Args:
output: If specified, only auto-allocate against the given built output
Returns a list of dict objects with keys like:
@ -422,7 +432,7 @@ class Build(MPTTModel):
See: getAutoAllocations()
"""
allocations = self.getAutoAllocations()
allocations = self.getAutoAllocations(output)
for item in allocations:
# Create a new allocation

View File

@ -25,13 +25,13 @@ InvenTree | Allocate Parts
<table class='table table-striped table-condensed' id='build-item-list' data-toolbar='#build-item-toolbar'></table>
-->
<h4>{% trans "Untracked Parts" %}</h4>
<h4>{% trans "Allocated Stock" %}</h4>
<div class="panel-group" id="build-output-accordion" role="tablist" aria-multiselectable="true">
{% include "build/allocation_card.html" %}
</div>
{% if build.incomplete_outputs %}
<h4>{% trans "Tracked Build Ouputs" %}</h4>
<h4>{% trans "Build Ouputs" %}</h4>
<div class="panel-group" id="build-output-accordion" role="tablist" aria-multiselectable="true">
{% for item in build.incomplete_outputs %}
{% include "build/allocation_card.html" with item=item %}

View File

@ -18,11 +18,10 @@
{% else %}
{% trans "Untracked items" %}
{% endif %}
</div>
</a>
</a>
</div>
<div class='col-sm-3'>
<div>
{% trans "Completed lines" %}:
<div id='output-progress-{{ pk }}'>
<span class='fas fa-spin fa-spinner'></span>
</div>

View File

@ -172,7 +172,7 @@ class BuildTest(TestCase):
self.assertEqual(len(allocations), 1)
self.build.autoAllocate()
self.build.auto_allocate()
self.assertEqual(BuildItem.objects.count(), 1)
self.assertTrue(self.build.isPartFullyAllocated(self.sub_part_2))

View File

@ -93,12 +93,24 @@ class BuildAutoAllocate(AjaxUpdateView):
"""
model = Build
form_class = forms.ConfirmBuildForm
form_class = forms.AutoAllocateForm
context_object_name = 'build'
ajax_form_title = _('Allocate Stock')
ajax_template_name = 'build/auto_allocate.html'
role_required = 'build.change'
def get_initial(self):
initials = super().get_initial()
# Pointing to a particular build output?
output = self.get_param('output')
if output:
initials['output_id'] = output
return initials
def get_context_data(self, *args, **kwargs):
""" Get the context data for form rendering. """
@ -125,14 +137,23 @@ class BuildAutoAllocate(AjaxUpdateView):
confirm = request.POST.get('confirm', False)
output = None
output_id = request.POST.get('output_id', None)
if output_id:
try:
output = StockItem.objects.get(pk=output_id)
except (ValueError, StockItem.DoesNotExist):
pass
valid = False
if confirm is False:
if confirm:
build.auto_allocate(output)
valid = True
else:
form.errors['confirm'] = [_('Confirm stock allocation')]
form.non_field_errors = [_('Check the confirmation box at the bottom of the list')]
else:
build.autoAllocate()
valid = True
data = {
'form_valid': valid,

View File

@ -55,21 +55,23 @@ function makeBuildOutputActionButtons(output, buildInfo) {
// Add a button to "auto allocate" against the particular build output
html += makeIconButton(
'fa-clipboard-check icon-blue', 'button-output-auto', outputId,
'{% trans "Allocate stock items to this output" %}',
'fa-magic icon-blue', 'button-output-auto', outputId,
'{% trans "Auto-allocate stock items to this output" %}',
{
disabled: true,
}
);
// Add a button to "complete" the particular build output
html += makeIconButton(
'fa-tools icon-green', 'button-output-complete', outputId,
'{% trans "Complete build output" %}',
{
disabled: true
}
);
if (output) {
// Add a button to "complete" the particular build output
html += makeIconButton(
'fa-check icon-green', 'button-output-complete', outputId,
'{% trans "Complete build output" %}',
{
disabled: true
}
);
}
// Add a button to "cancel" the particular build output (unallocate)
html += makeIconButton(
@ -77,14 +79,18 @@ function makeBuildOutputActionButtons(output, buildInfo) {
'{% trans "Unallocate stock from build output" %}',
);
// Add a button to "delete" the particular build output
html += makeIconButton(
'fa-trash-alt icon-red', 'button-output-delete', outputId,
'{% trans "Delete build output" %}',
);
if (output) {
// Add a button to "delete" the particular build output
html += makeIconButton(
'fa-trash-alt icon-red', 'button-output-delete', outputId,
'{% trans "Delete build output" %}',
);
// Add a button to "destroy" the particular build output (mark as damaged, scrap)
// TODO
}
// Add a button to "destroy" the particular build output (mark as damaged, scrap)
// TODO
html += '</div>';