Add confirmation to cancel a build

This commit is contained in:
Oliver Walters 2019-05-14 18:20:54 +10:00
parent e87f545d75
commit 9986df2074
3 changed files with 37 additions and 10 deletions

View File

@ -58,6 +58,18 @@ class CompleteBuildForm(HelperForm):
]
class CancelBuildForm(HelperForm):
""" Form for cancelling a build """
confirm_cancel = forms.BooleanField(required=False, help_text='Confirm build cancellation')
class Meta:
model = Build
fields = [
'confirm_cancel'
]
class EditBuildItemForm(HelperForm):
""" Form for adding a new BuildItem to a Build """

View File

@ -1,3 +1,7 @@
{% extends "modal_form.html" %}
{% block pre_form_content %}
Are you sure you wish to cancel this build?
{% include "modal_csrf.html" %}
{% endblock %}

View File

@ -16,6 +16,7 @@ from . import forms
from stock.models import StockLocation, StockItem
from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView, AjaxDeleteView
from InvenTree.helpers import str2bool
class BuildIndex(ListView):
@ -41,31 +42,41 @@ class BuildIndex(ListView):
return context
class BuildCancel(AjaxView):
class BuildCancel(AjaxUpdateView):
""" View to cancel a Build.
Provides a cancellation information dialog
"""
model = Build
ajax_template_name = 'build/cancel.html'
ajax_form_title = 'Cancel Build'
context_object_name = 'build'
fields = []
form_class = forms.CancelBuildForm
def post(self, request, *args, **kwargs):
""" Handle POST request. Mark the build status as CANCELLED """
build = get_object_or_404(Build, pk=self.kwargs['pk'])
build = self.get_object()
build.cancelBuild(request.user)
form = self.get_form()
return self.renderJsonResponse(request, None)
valid = form.is_valid()
def get_data(self):
""" Provide JSON context data. """
return {
confirm = str2bool(request.POST.get('confirm_cancel', False))
if confirm:
build.cancelBuild(request.user)
else:
form.errors['confirm_cancel'] = ['Confirm build cancellation']
valid = False
data = {
'form_valid': valid,
'danger': 'Build was cancelled'
}
return self.renderJsonResponse(request, form, data=data)
class BuildAutoAllocate(AjaxUpdateView):
""" View to auto-allocate parts for a build.
@ -217,7 +228,7 @@ class BuildComplete(AjaxUpdateView):
form = self.get_form()
confirm = request.POST.get('confirm', False)
confirm = str2bool(request.POST.get('confirm', False))
loc_id = request.POST.get('location', None)