mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Further build tweaks / improvements
This commit is contained in:
parent
f5d0d54ded
commit
05613b9642
@ -383,9 +383,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
|
||||
if valid:
|
||||
|
||||
# Save the object to the database
|
||||
self.save(self.form)
|
||||
|
||||
self.object = self.get_object()
|
||||
self.object = self.save(self.form)
|
||||
|
||||
# Return the PK of the newly-created object
|
||||
data['pk'] = self.object.pk
|
||||
|
@ -322,7 +322,8 @@ class Build(MPTTModel):
|
||||
# No issues!
|
||||
return True
|
||||
|
||||
def completeBuild(self, user):
|
||||
@transaction.atomic
|
||||
def complete_build(self, user):
|
||||
"""
|
||||
Mark this build as complete
|
||||
"""
|
||||
@ -335,6 +336,11 @@ class Build(MPTTModel):
|
||||
self.status = BuildStatus.COMPLETE
|
||||
self.save()
|
||||
|
||||
# Ensure that there are no longer any BuildItem objects
|
||||
# which point to thie Build Order
|
||||
self.allocated_stock.all().delete()
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def cancelBuild(self, user):
|
||||
""" Mark the Build as CANCELLED
|
||||
|
@ -15,6 +15,11 @@ InvenTree | Allocate Parts
|
||||
|
||||
<hr>
|
||||
|
||||
{% if build.is_complete %}
|
||||
<div class='alert alert-block alert-success'>
|
||||
{% trans "Build order has been completed" %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class='btn-group' role='group'>
|
||||
<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" %}
|
||||
@ -22,25 +27,27 @@ InvenTree | Allocate Parts
|
||||
<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>
|
||||
<button class='btn btn-danger' type='button' id='btn-unallocate' title='{% trans "Unallocate stock" %}'>
|
||||
<span class='fas fa-minus-circle'></span> {% trans "Unallocate Stock" %}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
{% if build.incomplete_outputs %}
|
||||
<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 %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class='alert alert-block alert-info'>
|
||||
<b>{% trans "Create a new build output" %}</b><br>
|
||||
{% trans "No incomplete build outputs remain." %}<br>
|
||||
{% trans "Create a new build output using the button above" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!---
|
||||
<div id='build-item-toolbar'>
|
||||
{% if build.status == BuildStatus.PENDING %}
|
||||
<div class='btn-group'>
|
||||
<button class='btn btn-primary' type='button' id='btn-order-parts' title='Order Parts'><span class='fas fa-shopping-cart'></span> {% trans "Order Parts" %}</button>
|
||||
<button class='btn btn-primary' type='button' id='btn-allocate' title='{% trans "Automatically allocate stock" %}'><span class='fas fa-magic'></span> {% trans "Auto Allocate" %}</button>
|
||||
<button class='btn btn-danger' type='button' id='btn-unallocate' title='Unallocate Stock'><span class='fas fa-minus-circle'></span> {% trans "Unallocate" %}</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
-->
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
@ -7,11 +7,19 @@
|
||||
<div class="panel-heading" role="tab" id="heading-{{ pk }}">
|
||||
<div class="panel-title">
|
||||
<div class='row'>
|
||||
<div class='col-sm-6'>
|
||||
<a class='collapsed' aria-expanded='false' role="button" data-toggle="collapse" data-parent="#build-output-accordion" href="#collapse-{{ pk }}" aria-controls="collapse-{{ pk }}">
|
||||
<span class='fas fa-caret-right'></span> {{ item }}
|
||||
</a>
|
||||
</div>
|
||||
<a class='collapsed' aria-expanded='false' role="button" data-toggle="collapse" data-parent="#build-output-accordion" href="#collapse-{{ pk }}" aria-controls="collapse-{{ pk }}">
|
||||
<div class='col-sm-4'>
|
||||
<span class='fas fa-caret-right'></span>
|
||||
{{ item.part.full_name }}
|
||||
</div>
|
||||
<div class='col-sm-2'>
|
||||
{% if item.serial %}
|
||||
# {{ item.serial }}
|
||||
{% else %}
|
||||
{{ item.quantity }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</a>
|
||||
<div class='col-sm-3'>
|
||||
<div>
|
||||
<div id='output-progress-{{ pk }}'>
|
||||
|
@ -404,6 +404,23 @@ class BuildComplete(AjaxUpdateView):
|
||||
ajax_form_title = _('Complete Build Order')
|
||||
ajax_template_name = 'build/complete.html'
|
||||
|
||||
def validate(self, build, form, **kwargs):
|
||||
|
||||
if not build.can_complete:
|
||||
form.add_error(None, _('Build order cannot be completed'))
|
||||
|
||||
def save(self, build, form, **kwargs):
|
||||
"""
|
||||
Perform the build completion step
|
||||
"""
|
||||
|
||||
build.complete_build(self.request.user)
|
||||
|
||||
def get_data(self):
|
||||
return {
|
||||
'success': _('Completed build order')
|
||||
}
|
||||
|
||||
|
||||
class BuildOutputComplete(AjaxUpdateView):
|
||||
"""
|
||||
@ -731,6 +748,34 @@ class BuildUpdate(AjaxUpdateView):
|
||||
ajax_template_name = 'modal_form.html'
|
||||
role_required = 'build.change'
|
||||
|
||||
def get_form(self):
|
||||
|
||||
form = super().get_form()
|
||||
|
||||
build = self.get_object()
|
||||
|
||||
# Fields which are included in the form, but hidden
|
||||
hidden = [
|
||||
'parent',
|
||||
'sales_order',
|
||||
]
|
||||
|
||||
if build.is_complete:
|
||||
# Fields which cannot be edited once the build has been completed
|
||||
|
||||
hidden += [
|
||||
'part',
|
||||
'quantity',
|
||||
'batch',
|
||||
'take_from',
|
||||
'destination',
|
||||
]
|
||||
|
||||
for field in hidden:
|
||||
form.fields[field].widget = HiddenInput()
|
||||
|
||||
return form
|
||||
|
||||
def get_data(self):
|
||||
return {
|
||||
'info': _('Edited build'),
|
||||
@ -765,7 +810,7 @@ class BuildItemDelete(AjaxDeleteView):
|
||||
|
||||
class BuildItemCreate(AjaxCreateView):
|
||||
"""
|
||||
View for allocating a StockItems to a build output.
|
||||
View for allocating a StockItem to a build output.
|
||||
"""
|
||||
|
||||
model = BuildItem
|
||||
|
@ -101,10 +101,10 @@ function makeBuildOutputActionButtons(output, buildInfo) {
|
||||
launchModalForm(
|
||||
`/build/${buildId}/complete-output/`,
|
||||
{
|
||||
success: reloadTable,
|
||||
data: {
|
||||
output: outputId,
|
||||
}
|
||||
},
|
||||
reload: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user