mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Remove old views / forms
This commit is contained in:
parent
14ef56785e
commit
283bf1682f
@ -155,59 +155,6 @@ class CompleteBuildForm(HelperForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CompleteBuildOutputForm(HelperForm):
|
|
||||||
"""
|
|
||||||
Form for completing a single build output
|
|
||||||
"""
|
|
||||||
|
|
||||||
field_prefix = {
|
|
||||||
'serial_numbers': 'fa-hashtag',
|
|
||||||
}
|
|
||||||
|
|
||||||
field_placeholder = {
|
|
||||||
}
|
|
||||||
|
|
||||||
location = forms.ModelChoiceField(
|
|
||||||
queryset=StockLocation.objects.all(),
|
|
||||||
label=_('Location'),
|
|
||||||
help_text=_('Location of completed parts'),
|
|
||||||
)
|
|
||||||
|
|
||||||
stock_status = forms.ChoiceField(
|
|
||||||
label=_('Status'),
|
|
||||||
help_text=_('Build output stock status'),
|
|
||||||
initial=StockStatus.OK,
|
|
||||||
choices=StockStatus.items(),
|
|
||||||
)
|
|
||||||
|
|
||||||
confirm_incomplete = forms.BooleanField(
|
|
||||||
required=False,
|
|
||||||
label=_('Confirm incomplete'),
|
|
||||||
help_text=_("Confirm completion with incomplete stock allocation")
|
|
||||||
)
|
|
||||||
|
|
||||||
confirm = forms.BooleanField(required=True, label=_('Confirm'), help_text=_('Confirm build completion'))
|
|
||||||
|
|
||||||
output = forms.ModelChoiceField(
|
|
||||||
queryset=StockItem.objects.all(), # Queryset is narrowed in the view
|
|
||||||
widget=forms.HiddenInput(),
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Build
|
|
||||||
fields = [
|
|
||||||
'location',
|
|
||||||
'output',
|
|
||||||
'stock_status',
|
|
||||||
'confirm',
|
|
||||||
'confirm_incomplete',
|
|
||||||
]
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class CancelBuildForm(HelperForm):
|
class CancelBuildForm(HelperForm):
|
||||||
""" Form for cancelling a build """
|
""" Form for cancelling a build """
|
||||||
|
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
{% load i18n %}
|
|
||||||
{% load inventree_extras %}
|
|
||||||
|
|
||||||
{% define item.pk as pk %}
|
|
||||||
|
|
||||||
<div class="panel panel-default" id='allocation-panel-{{ pk }}'>
|
|
||||||
<div class="panel-heading" role="tab" id="heading-{{ pk }}">
|
|
||||||
<div class="panel-title">
|
|
||||||
<div class='row'>
|
|
||||||
{% if tracked_items %}
|
|
||||||
<a class='collapsed' aria-expanded='false' role="button" data-toggle="collapse" data-parent="#build-output-accordion" href="#collapse-{{ pk }}" aria-controls="collapse-{{ pk }}">
|
|
||||||
{% endif %}
|
|
||||||
<div class='col-sm-4'>
|
|
||||||
{% if tracked_items %}
|
|
||||||
<span class='fas fa-caret-right'></span>
|
|
||||||
{% endif %}
|
|
||||||
{{ item.part.full_name }}
|
|
||||||
</div>
|
|
||||||
<div class='col-sm-2'>
|
|
||||||
{% if item.serial %}
|
|
||||||
{% trans "Serial Number" %}: {{ item.serial }}
|
|
||||||
{% else %}
|
|
||||||
{% trans "Quantity" %}: {% decimal item.quantity %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% if tracked_items %}
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
<div class='col-sm-3'>
|
|
||||||
<div>
|
|
||||||
<div id='output-progress-{{ pk }}'>
|
|
||||||
{% if tracked_items %}
|
|
||||||
<span class='fas fa-spin fa-spinner'></span>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class='col-sm-3'>
|
|
||||||
<div class='btn-group float-right' id='output-actions-{{ pk }}'>
|
|
||||||
<span class='fas fa-spin fa-spinner'></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="collapse-{{ pk }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-{{ pk }}">
|
|
||||||
<div class="panel-body">
|
|
||||||
<table class='table table-striped table-condensed' id='allocation-table-{{ pk }}'></table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -1,53 +0,0 @@
|
|||||||
{% extends "modal_form.html" %}
|
|
||||||
{% load inventree_extras %}
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block pre_form_content %}
|
|
||||||
|
|
||||||
{% if not build.has_tracked_bom_items %}
|
|
||||||
{% elif fully_allocated %}
|
|
||||||
<div class='alert alert-block alert-success'>
|
|
||||||
{% trans "Stock allocation is complete for this output" %}
|
|
||||||
</div>
|
|
||||||
{% else %}
|
|
||||||
<div class='alert alert-block alert-danger'>
|
|
||||||
<h4>{% trans "Stock allocation is incomplete" %}</h4>
|
|
||||||
|
|
||||||
<div class='panel-group'>
|
|
||||||
<div class='panel panel-default'>
|
|
||||||
<div class='panel panel-heading'>
|
|
||||||
<a data-toggle='collapse' href='#collapse-unallocated'>
|
|
||||||
{{ unallocated_parts|length }} {% trans "tracked parts have not been fully allocated" %}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class='panel-collapse collapse' id='collapse-unallocated'>
|
|
||||||
<div class='panel-body'>
|
|
||||||
<ul class='list-group'>
|
|
||||||
{% for part in unallocated_parts %}
|
|
||||||
<li class='list-group-item'>
|
|
||||||
{% include "hover_image.html" with image=part.image %} {{ part }}
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<div class='panel panel-info'>
|
|
||||||
<div class='panel-heading'>
|
|
||||||
{% trans "The following items will be created" %}
|
|
||||||
</div>
|
|
||||||
<div class='panel-content' style='padding-bottom:16px'>
|
|
||||||
{% include "hover_image.html" with image=build.part.image %}
|
|
||||||
{% if output.serialized %}
|
|
||||||
{{ output.part.full_name }} - {% trans "Serial Number" %} {{ output.serial }}
|
|
||||||
{% else %}
|
|
||||||
{% decimal output.quantity %} x {{ output.part.full_name }}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
@ -11,7 +11,6 @@ build_detail_urls = [
|
|||||||
url(r'^delete/', views.BuildDelete.as_view(), name='build-delete'),
|
url(r'^delete/', views.BuildDelete.as_view(), name='build-delete'),
|
||||||
url(r'^create-output/', views.BuildOutputCreate.as_view(), name='build-output-create'),
|
url(r'^create-output/', views.BuildOutputCreate.as_view(), name='build-output-create'),
|
||||||
url(r'^delete-output/', views.BuildOutputDelete.as_view(), name='build-output-delete'),
|
url(r'^delete-output/', views.BuildOutputDelete.as_view(), name='build-output-delete'),
|
||||||
url(r'^complete-output/', views.BuildOutputComplete.as_view(), name='build-output-complete'),
|
|
||||||
url(r'^complete/', views.BuildComplete.as_view(), name='build-complete'),
|
url(r'^complete/', views.BuildComplete.as_view(), name='build-complete'),
|
||||||
|
|
||||||
url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'),
|
url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'),
|
||||||
|
@ -278,176 +278,6 @@ class BuildComplete(AjaxUpdateView):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BuildOutputComplete(AjaxUpdateView):
|
|
||||||
"""
|
|
||||||
View to mark a particular build output as Complete.
|
|
||||||
|
|
||||||
- Notifies the user of which parts will be removed from stock.
|
|
||||||
- Assignes (tracked) allocated items from stock to the build output
|
|
||||||
- Deletes pending BuildItem objects
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = Build
|
|
||||||
form_class = forms.CompleteBuildOutputForm
|
|
||||||
context_object_name = "build"
|
|
||||||
ajax_form_title = _("Complete Build Output")
|
|
||||||
ajax_template_name = "build/complete_output.html"
|
|
||||||
|
|
||||||
def get_form(self):
|
|
||||||
|
|
||||||
build = self.get_object()
|
|
||||||
|
|
||||||
form = super().get_form()
|
|
||||||
|
|
||||||
# Extract the build output object
|
|
||||||
output = None
|
|
||||||
output_id = form['output'].value()
|
|
||||||
|
|
||||||
try:
|
|
||||||
output = StockItem.objects.get(pk=output_id)
|
|
||||||
except (ValueError, StockItem.DoesNotExist):
|
|
||||||
pass
|
|
||||||
|
|
||||||
if output:
|
|
||||||
if build.isFullyAllocated(output):
|
|
||||||
form.fields['confirm_incomplete'].widget = HiddenInput()
|
|
||||||
|
|
||||||
return form
|
|
||||||
|
|
||||||
def validate(self, build, form, **kwargs):
|
|
||||||
"""
|
|
||||||
Custom validation steps for the BuildOutputComplete" form
|
|
||||||
"""
|
|
||||||
|
|
||||||
data = form.cleaned_data
|
|
||||||
|
|
||||||
output = data.get('output', None)
|
|
||||||
|
|
||||||
stock_status = data.get('stock_status', StockStatus.OK)
|
|
||||||
|
|
||||||
# Any "invalid" stock status defaults to OK
|
|
||||||
try:
|
|
||||||
stock_status = int(stock_status)
|
|
||||||
except (ValueError):
|
|
||||||
stock_status = StockStatus.OK
|
|
||||||
|
|
||||||
if int(stock_status) not in StockStatus.keys():
|
|
||||||
form.add_error('stock_status', _('Invalid stock status value selected'))
|
|
||||||
|
|
||||||
if output:
|
|
||||||
|
|
||||||
quantity = data.get('quantity', None)
|
|
||||||
|
|
||||||
if quantity and quantity > output.quantity:
|
|
||||||
form.add_error('quantity', _('Quantity to complete cannot exceed build output quantity'))
|
|
||||||
|
|
||||||
if not build.isFullyAllocated(output):
|
|
||||||
confirm = str2bool(data.get('confirm_incomplete', False))
|
|
||||||
|
|
||||||
if not confirm:
|
|
||||||
form.add_error('confirm_incomplete', _('Confirm completion of incomplete build'))
|
|
||||||
|
|
||||||
else:
|
|
||||||
form.add_error(None, _('Build output must be specified'))
|
|
||||||
|
|
||||||
def get_initial(self):
|
|
||||||
""" Get initial form data for the CompleteBuild form
|
|
||||||
|
|
||||||
- If the part being built has a default location, pre-select that location
|
|
||||||
"""
|
|
||||||
|
|
||||||
initials = super().get_initial()
|
|
||||||
build = self.get_object()
|
|
||||||
|
|
||||||
if build.part.default_location is not None:
|
|
||||||
try:
|
|
||||||
location = StockLocation.objects.get(pk=build.part.default_location.id)
|
|
||||||
initials['location'] = location
|
|
||||||
except StockLocation.DoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
output = self.get_param('output', None)
|
|
||||||
|
|
||||||
if output:
|
|
||||||
try:
|
|
||||||
output = StockItem.objects.get(pk=output)
|
|
||||||
except (ValueError, StockItem.DoesNotExist):
|
|
||||||
output = None
|
|
||||||
|
|
||||||
# Output has not been supplied? Try to "guess"
|
|
||||||
if not output:
|
|
||||||
|
|
||||||
incomplete = build.get_build_outputs(complete=False)
|
|
||||||
|
|
||||||
if incomplete.count() == 1:
|
|
||||||
output = incomplete[0]
|
|
||||||
|
|
||||||
if output is not None:
|
|
||||||
initials['output'] = output
|
|
||||||
|
|
||||||
initials['location'] = build.destination
|
|
||||||
|
|
||||||
return initials
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
"""
|
|
||||||
Get context data for passing to the rendered form
|
|
||||||
|
|
||||||
- Build information is required
|
|
||||||
"""
|
|
||||||
|
|
||||||
build = self.get_object()
|
|
||||||
|
|
||||||
context = {}
|
|
||||||
|
|
||||||
# Build object
|
|
||||||
context['build'] = build
|
|
||||||
|
|
||||||
form = self.get_form()
|
|
||||||
|
|
||||||
output = form['output'].value()
|
|
||||||
|
|
||||||
if output:
|
|
||||||
try:
|
|
||||||
output = StockItem.objects.get(pk=output)
|
|
||||||
context['output'] = output
|
|
||||||
context['fully_allocated'] = build.isFullyAllocated(output)
|
|
||||||
context['allocated_parts'] = build.allocatedParts(output)
|
|
||||||
context['unallocated_parts'] = build.unallocatedParts(output)
|
|
||||||
except (ValueError, StockItem.DoesNotExist):
|
|
||||||
pass
|
|
||||||
|
|
||||||
return context
|
|
||||||
|
|
||||||
def save(self, build, form, **kwargs):
|
|
||||||
|
|
||||||
data = form.cleaned_data
|
|
||||||
|
|
||||||
location = data.get('location', None)
|
|
||||||
output = data.get('output', None)
|
|
||||||
stock_status = data.get('stock_status', StockStatus.OK)
|
|
||||||
|
|
||||||
# Any "invalid" stock status defaults to OK
|
|
||||||
try:
|
|
||||||
stock_status = int(stock_status)
|
|
||||||
except (ValueError):
|
|
||||||
stock_status = StockStatus.OK
|
|
||||||
|
|
||||||
# Complete the build output
|
|
||||||
build.complete_build_output(
|
|
||||||
output,
|
|
||||||
self.request.user,
|
|
||||||
location=location,
|
|
||||||
status=stock_status,
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_data(self):
|
|
||||||
""" Provide feedback data back to the form """
|
|
||||||
return {
|
|
||||||
'success': _('Build output completed')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class BuildDetail(InvenTreeRoleMixin, DetailView):
|
class BuildDetail(InvenTreeRoleMixin, DetailView):
|
||||||
""" Detail view of a single Build object. """
|
""" Detail view of a single Build object. """
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user