diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py
index 487500e3d7..3891cc512a 100644
--- a/InvenTree/build/models.py
+++ b/InvenTree/build/models.py
@@ -76,6 +76,23 @@ class Build(models.Model):
notes = models.TextField(blank=True)
""" Notes attached to each build output """
+ def cancelBuild(self):
+ """ Mark the Build as CANCELLED
+
+ - Delete any pending BuildItem objects (but do not remove items from stock)
+ """
+ print("cancelled!")
+
+
+ def completeBuild(self):
+ """ Mark the Build as COMPLETE
+
+ - Takes allocated items from stock
+ - Delete pending BuildItem objects
+ """
+
+ print("complete!!!!")
+
@property
def required_parts(self):
""" Returns a dict of parts required to build this part (BOM) """
diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html
index aca7a3ebba..ea33932d87 100644
--- a/InvenTree/build/templates/build/allocate.html
+++ b/InvenTree/build/templates/build/allocate.html
@@ -12,6 +12,10 @@
+
+
+
+
{% endblock %}
{% block js_load %}
@@ -32,4 +36,14 @@
}
);
+ $("#complete-build").on('click', function() {
+ launchModalForm(
+ "{% url 'build-complete' build.id %}",
+ {
+ reload: true,
+ submit_text: "Complete Build",
+ }
+ );
+ });
+
{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/build/templates/build/complete.html b/InvenTree/build/templates/build/complete.html
new file mode 100644
index 0000000000..6cf26c2a6c
--- /dev/null
+++ b/InvenTree/build/templates/build/complete.html
@@ -0,0 +1 @@
+Mark as COMPLETE
\ No newline at end of file
diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html
index 9b239767c0..1960ed4ef5 100644
--- a/InvenTree/build/templates/build/detail.html
+++ b/InvenTree/build/templates/build/detail.html
@@ -118,7 +118,7 @@
launchModalForm("{% url 'build-cancel' build.id %}",
{
reload: true,
- submit_text: "Cancel",
+ submit_text: "Cancel Build",
});
});
{% endblock %}
diff --git a/InvenTree/build/urls.py b/InvenTree/build/urls.py
index 109616348d..162b9a613f 100644
--- a/InvenTree/build/urls.py
+++ b/InvenTree/build/urls.py
@@ -20,6 +20,7 @@ build_detail_urls = [
url(r'^edit/?', views.BuildUpdate.as_view(), name='build-edit'),
url(r'^allocate/?', views.BuildAllocate.as_view(), name='build-allocate'),
url(r'^cancel/?', views.BuildCancel.as_view(), name='build-cancel'),
+ url(r'^complete/?', views.BuildComplete.as_view(), name='build-complete'),
url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'),
]
diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py
index 07facc31f4..31e25c017f 100644
--- a/InvenTree/build/views.py
+++ b/InvenTree/build/views.py
@@ -47,7 +47,7 @@ class BuildCancel(AjaxView):
Provides a cancellation information dialog
"""
model = Build
- template_name = 'build/cancel.html'
+ ajax_template_name = 'build/cancel.html'
ajax_form_title = 'Cancel Build'
context_object_name = 'build'
fields = []
@@ -57,8 +57,7 @@ class BuildCancel(AjaxView):
build = get_object_or_404(Build, pk=self.kwargs['pk'])
- build.status = Build.CANCELLED
- build.save()
+ build.cancelBuild()
return self.renderJsonResponse(request, None)
@@ -69,6 +68,36 @@ class BuildCancel(AjaxView):
}
+class BuildComplete(AjaxView):
+ """ View to mark a build as Complete.
+
+ - Notifies the user of which parts will be removed from stock.
+ - Removes allocated items from stock
+ - Deletes pending BuildItem objects
+ """
+
+ model = Build
+ ajax_template_name = "build/complete.html"
+ ajax_form_title = "Complete Build"
+ context_object_name = "build"
+ fields = []
+
+ def post(self, request, *args, **kwargs):
+ """ Handle POST request. Mark the build as COMPLETE """
+
+ build = get_object_or_404(Build, pk=self.kwargs['pk'])
+
+ build.complete()
+
+ return self.renderJsonResponse(request, None)
+
+ def get_data(self):
+ """ Provide feedback data back to the form """
+ return {
+ 'info': 'Build marked as COMPLETE'
+ }
+
+
class BuildDetail(DetailView):
""" Detail view of a single Build object. """
model = Build
diff --git a/InvenTree/static/script/inventree/build.js b/InvenTree/static/script/inventree/build.js
index a0b52d739a..f5c41e7662 100644
--- a/InvenTree/static/script/inventree/build.js
+++ b/InvenTree/static/script/inventree/build.js
@@ -10,9 +10,10 @@ function makeBuildTable(build_table, options) {
*
*/
- table.bootstrapTable({
+ build_table.bootstrapTable({
sortable: false,
detailView: true,
+ showHeader: false,
detailFormatter: function(index, row, element) {
return makeAllocationTable({
part: row.pk
@@ -45,16 +46,16 @@ function makeBuildTable(build_table, options) {
field: 'allocated',
title: 'Allocated to Build',
formatter: function(value, row, index, field) {
- var html = "";
+ var html = "Allocated ";
var url = options.new_item_url;
url += "?build=" + options.build + "&part=" + row.sub_part;
if (value) {
- html = value;
+ html += value;
} else {
- html = "0";
+ html += "0";
}
html += " of ";
@@ -62,7 +63,7 @@ function makeBuildTable(build_table, options) {
html += "";
- html += "";
+ html += "";
html += "
";