mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added some more buttons, etc
This commit is contained in:
parent
5e0d1fe25a
commit
b38fde85f2
@ -90,18 +90,26 @@ class UnallocateBuildForm(HelperForm):
|
|||||||
model = Build
|
model = Build
|
||||||
fields = [
|
fields = [
|
||||||
'confirm',
|
'confirm',
|
||||||
|
'output_id',
|
||||||
|
'part_id',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ConfirmBuildForm(HelperForm):
|
class AutoAllocateForm(HelperForm):
|
||||||
""" Form for auto-allocation of stock to a build """
|
""" Form for auto-allocation of stock to a build """
|
||||||
|
|
||||||
confirm = forms.BooleanField(required=False, help_text=_('Confirm'))
|
confirm = forms.BooleanField(required=False, help_text=_('Confirm'))
|
||||||
|
|
||||||
|
output_id = forms.IntegerField(
|
||||||
|
required=False,
|
||||||
|
widget=forms.HiddenInput()
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Build
|
model = Build
|
||||||
fields = [
|
fields = [
|
||||||
'confirm'
|
'confirm',
|
||||||
|
'output_id',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ class Build(MPTTModel):
|
|||||||
self.status = BuildStatus.CANCELLED
|
self.status = BuildStatus.CANCELLED
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def getAutoAllocations(self):
|
def getAutoAllocations(self, output):
|
||||||
""" Return a list of parts which will be allocated
|
""" Return a list of parts which will be allocated
|
||||||
using the 'AutoAllocate' function.
|
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)
|
- 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)
|
- If there are multiple StockItems available, ignore (leave up to the user)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
output: A stock item (build output) to auto-allocate against
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A list object containing the StockItem objects to be allocated (and the quantities)
|
A list object containing the StockItem objects to be allocated (and the quantities)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allocations = []
|
allocations = []
|
||||||
|
|
||||||
|
"""
|
||||||
|
Iterate through each item in the BOM
|
||||||
|
"""
|
||||||
for item in self.part.bom_items.all().prefetch_related('sub_part'):
|
for item in self.part.bom_items.all().prefetch_related('sub_part'):
|
||||||
|
|
||||||
# How many parts required for this build?
|
# How many parts required for this build?
|
||||||
@ -409,8 +415,12 @@ class Build(MPTTModel):
|
|||||||
output.delete()
|
output.delete()
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def autoAllocate(self):
|
def auto_allocate(self, output=None):
|
||||||
""" Run auto-allocation routine to allocate StockItems to this Build.
|
"""
|
||||||
|
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:
|
Returns a list of dict objects with keys like:
|
||||||
|
|
||||||
@ -422,7 +432,7 @@ class Build(MPTTModel):
|
|||||||
See: getAutoAllocations()
|
See: getAutoAllocations()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allocations = self.getAutoAllocations()
|
allocations = self.getAutoAllocations(output)
|
||||||
|
|
||||||
for item in allocations:
|
for item in allocations:
|
||||||
# Create a new allocation
|
# Create a new allocation
|
||||||
|
@ -25,13 +25,13 @@ InvenTree | Allocate Parts
|
|||||||
<table class='table table-striped table-condensed' id='build-item-list' data-toolbar='#build-item-toolbar'></table>
|
<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">
|
<div class="panel-group" id="build-output-accordion" role="tablist" aria-multiselectable="true">
|
||||||
{% include "build/allocation_card.html" %}
|
{% include "build/allocation_card.html" %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if build.incomplete_outputs %}
|
{% 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">
|
<div class="panel-group" id="build-output-accordion" role="tablist" aria-multiselectable="true">
|
||||||
{% for item in build.incomplete_outputs %}
|
{% for item in build.incomplete_outputs %}
|
||||||
{% include "build/allocation_card.html" with item=item %}
|
{% include "build/allocation_card.html" with item=item %}
|
||||||
|
@ -18,11 +18,10 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
{% trans "Untracked items" %}
|
{% trans "Untracked items" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</a>
|
||||||
</a>
|
</div>
|
||||||
<div class='col-sm-3'>
|
<div class='col-sm-3'>
|
||||||
<div>
|
<div>
|
||||||
{% trans "Completed lines" %}:
|
|
||||||
<div id='output-progress-{{ pk }}'>
|
<div id='output-progress-{{ pk }}'>
|
||||||
<span class='fas fa-spin fa-spinner'></span>
|
<span class='fas fa-spin fa-spinner'></span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -172,7 +172,7 @@ class BuildTest(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(len(allocations), 1)
|
self.assertEqual(len(allocations), 1)
|
||||||
|
|
||||||
self.build.autoAllocate()
|
self.build.auto_allocate()
|
||||||
self.assertEqual(BuildItem.objects.count(), 1)
|
self.assertEqual(BuildItem.objects.count(), 1)
|
||||||
self.assertTrue(self.build.isPartFullyAllocated(self.sub_part_2))
|
self.assertTrue(self.build.isPartFullyAllocated(self.sub_part_2))
|
||||||
|
|
||||||
|
@ -93,12 +93,24 @@ class BuildAutoAllocate(AjaxUpdateView):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
model = Build
|
model = Build
|
||||||
form_class = forms.ConfirmBuildForm
|
form_class = forms.AutoAllocateForm
|
||||||
context_object_name = 'build'
|
context_object_name = 'build'
|
||||||
ajax_form_title = _('Allocate Stock')
|
ajax_form_title = _('Allocate Stock')
|
||||||
ajax_template_name = 'build/auto_allocate.html'
|
ajax_template_name = 'build/auto_allocate.html'
|
||||||
role_required = 'build.change'
|
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):
|
def get_context_data(self, *args, **kwargs):
|
||||||
""" Get the context data for form rendering. """
|
""" Get the context data for form rendering. """
|
||||||
|
|
||||||
@ -125,14 +137,23 @@ class BuildAutoAllocate(AjaxUpdateView):
|
|||||||
|
|
||||||
confirm = request.POST.get('confirm', False)
|
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
|
valid = False
|
||||||
|
|
||||||
if confirm is False:
|
if confirm:
|
||||||
|
build.auto_allocate(output)
|
||||||
|
valid = True
|
||||||
|
else:
|
||||||
form.errors['confirm'] = [_('Confirm stock allocation')]
|
form.errors['confirm'] = [_('Confirm stock allocation')]
|
||||||
form.non_field_errors = [_('Check the confirmation box at the bottom of the list')]
|
form.non_field_errors = [_('Check the confirmation box at the bottom of the list')]
|
||||||
else:
|
|
||||||
build.autoAllocate()
|
|
||||||
valid = True
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'form_valid': valid,
|
'form_valid': valid,
|
||||||
|
@ -55,21 +55,23 @@ function makeBuildOutputActionButtons(output, buildInfo) {
|
|||||||
|
|
||||||
// Add a button to "auto allocate" against the particular build output
|
// Add a button to "auto allocate" against the particular build output
|
||||||
html += makeIconButton(
|
html += makeIconButton(
|
||||||
'fa-clipboard-check icon-blue', 'button-output-auto', outputId,
|
'fa-magic icon-blue', 'button-output-auto', outputId,
|
||||||
'{% trans "Allocate stock items to this output" %}',
|
'{% trans "Auto-allocate stock items to this output" %}',
|
||||||
{
|
{
|
||||||
disabled: true,
|
disabled: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add a button to "complete" the particular build output
|
if (output) {
|
||||||
html += makeIconButton(
|
// Add a button to "complete" the particular build output
|
||||||
'fa-tools icon-green', 'button-output-complete', outputId,
|
html += makeIconButton(
|
||||||
'{% trans "Complete build output" %}',
|
'fa-check icon-green', 'button-output-complete', outputId,
|
||||||
{
|
'{% trans "Complete build output" %}',
|
||||||
disabled: true
|
{
|
||||||
}
|
disabled: true
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Add a button to "cancel" the particular build output (unallocate)
|
// Add a button to "cancel" the particular build output (unallocate)
|
||||||
html += makeIconButton(
|
html += makeIconButton(
|
||||||
@ -77,14 +79,18 @@ function makeBuildOutputActionButtons(output, buildInfo) {
|
|||||||
'{% trans "Unallocate stock from build output" %}',
|
'{% trans "Unallocate stock from build output" %}',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add a button to "delete" the particular build output
|
if (output) {
|
||||||
html += makeIconButton(
|
// Add a button to "delete" the particular build output
|
||||||
'fa-trash-alt icon-red', 'button-output-delete', outputId,
|
html += makeIconButton(
|
||||||
'{% trans "Delete build output" %}',
|
'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>';
|
html += '</div>';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user