mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-04 14:28:48 +00:00
Add confirmation to cancel a build
This commit is contained in:
parent
e87f545d75
commit
9986df2074
@ -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):
|
class EditBuildItemForm(HelperForm):
|
||||||
""" Form for adding a new BuildItem to a Build """
|
""" Form for adding a new BuildItem to a Build """
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
{% extends "modal_form.html" %}
|
||||||
|
|
||||||
|
{% block pre_form_content %}
|
||||||
|
|
||||||
Are you sure you wish to cancel this build?
|
Are you sure you wish to cancel this build?
|
||||||
|
|
||||||
{% include "modal_csrf.html" %}
|
{% endblock %}
|
@ -16,6 +16,7 @@ from . import forms
|
|||||||
from stock.models import StockLocation, StockItem
|
from stock.models import StockLocation, StockItem
|
||||||
|
|
||||||
from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView, AjaxDeleteView
|
from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView, AjaxDeleteView
|
||||||
|
from InvenTree.helpers import str2bool
|
||||||
|
|
||||||
|
|
||||||
class BuildIndex(ListView):
|
class BuildIndex(ListView):
|
||||||
@ -41,31 +42,41 @@ class BuildIndex(ListView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class BuildCancel(AjaxView):
|
class BuildCancel(AjaxUpdateView):
|
||||||
""" View to cancel a Build.
|
""" View to cancel a Build.
|
||||||
Provides a cancellation information dialog
|
Provides a cancellation information dialog
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model = Build
|
model = Build
|
||||||
ajax_template_name = 'build/cancel.html'
|
ajax_template_name = 'build/cancel.html'
|
||||||
ajax_form_title = 'Cancel Build'
|
ajax_form_title = 'Cancel Build'
|
||||||
context_object_name = 'build'
|
context_object_name = 'build'
|
||||||
fields = []
|
form_class = forms.CancelBuildForm
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
""" Handle POST request. Mark the build status as CANCELLED """
|
""" 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):
|
confirm = str2bool(request.POST.get('confirm_cancel', False))
|
||||||
""" Provide JSON context data. """
|
|
||||||
return {
|
if confirm:
|
||||||
|
build.cancelBuild(request.user)
|
||||||
|
else:
|
||||||
|
form.errors['confirm_cancel'] = ['Confirm build cancellation']
|
||||||
|
valid = False
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'form_valid': valid,
|
||||||
'danger': 'Build was cancelled'
|
'danger': 'Build was cancelled'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return self.renderJsonResponse(request, form, data=data)
|
||||||
|
|
||||||
|
|
||||||
class BuildAutoAllocate(AjaxUpdateView):
|
class BuildAutoAllocate(AjaxUpdateView):
|
||||||
""" View to auto-allocate parts for a build.
|
""" View to auto-allocate parts for a build.
|
||||||
@ -217,7 +228,7 @@ class BuildComplete(AjaxUpdateView):
|
|||||||
|
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
|
|
||||||
confirm = request.POST.get('confirm', False)
|
confirm = str2bool(request.POST.get('confirm', False))
|
||||||
|
|
||||||
loc_id = request.POST.get('location', None)
|
loc_id = request.POST.get('location', None)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user