2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 04:56:45 +00:00

Skeleton code for Build cancel() and complete() functions

- BuildComplete view
This commit is contained in:
Oliver Walters 2019-04-30 20:39:01 +10:00
parent d518739643
commit fb89574c42
7 changed files with 72 additions and 9 deletions

View File

@ -76,6 +76,23 @@ class Build(models.Model):
notes = models.TextField(blank=True) notes = models.TextField(blank=True)
""" Notes attached to each build output """ """ 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 @property
def required_parts(self): def required_parts(self):
""" Returns a dict of parts required to build this part (BOM) """ """ Returns a dict of parts required to build this part (BOM) """

View File

@ -12,6 +12,10 @@
<table class='table table-striped' id='build-table'> <table class='table table-striped' id='build-table'>
</table> </table>
<div>
<button class='btn btn-warning' type='button' id='complete-build'>Complete Build</button>
</div>
{% endblock %} {% endblock %}
{% block js_load %} {% 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 %} {% endblock %}

View File

@ -0,0 +1 @@
Mark as COMPLETE

View File

@ -118,7 +118,7 @@
launchModalForm("{% url 'build-cancel' build.id %}", launchModalForm("{% url 'build-cancel' build.id %}",
{ {
reload: true, reload: true,
submit_text: "Cancel", submit_text: "Cancel Build",
}); });
}); });
{% endblock %} {% endblock %}

View File

@ -20,6 +20,7 @@ build_detail_urls = [
url(r'^edit/?', views.BuildUpdate.as_view(), name='build-edit'), url(r'^edit/?', views.BuildUpdate.as_view(), name='build-edit'),
url(r'^allocate/?', views.BuildAllocate.as_view(), name='build-allocate'), url(r'^allocate/?', views.BuildAllocate.as_view(), name='build-allocate'),
url(r'^cancel/?', views.BuildCancel.as_view(), name='build-cancel'), 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'), url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'),
] ]

View File

@ -47,7 +47,7 @@ class BuildCancel(AjaxView):
Provides a cancellation information dialog Provides a cancellation information dialog
""" """
model = Build model = Build
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 = [] fields = []
@ -57,8 +57,7 @@ class BuildCancel(AjaxView):
build = get_object_or_404(Build, pk=self.kwargs['pk']) build = get_object_or_404(Build, pk=self.kwargs['pk'])
build.status = Build.CANCELLED build.cancelBuild()
build.save()
return self.renderJsonResponse(request, None) 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): class BuildDetail(DetailView):
""" Detail view of a single Build object. """ """ Detail view of a single Build object. """
model = Build model = Build

View File

@ -10,9 +10,10 @@ function makeBuildTable(build_table, options) {
* *
*/ */
table.bootstrapTable({ build_table.bootstrapTable({
sortable: false, sortable: false,
detailView: true, detailView: true,
showHeader: false,
detailFormatter: function(index, row, element) { detailFormatter: function(index, row, element) {
return makeAllocationTable({ return makeAllocationTable({
part: row.pk part: row.pk
@ -45,16 +46,16 @@ function makeBuildTable(build_table, options) {
field: 'allocated', field: 'allocated',
title: 'Allocated to Build', title: 'Allocated to Build',
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
var html = ""; var html = "Allocated ";
var url = options.new_item_url; var url = options.new_item_url;
url += "?build=" + options.build + "&part=" + row.sub_part; url += "?build=" + options.build + "&part=" + row.sub_part;
if (value) { if (value) {
html = value; html += value;
} else { } else {
html = "0"; html += "0";
} }
html += " of "; html += " of ";
@ -62,7 +63,7 @@ function makeBuildTable(build_table, options) {
html += "<div class='btn-group' style='float: right;'>"; html += "<div class='btn-group' style='float: right;'>";
html += "<button class='btn btn-success btn-sm new-item-button' type='button' url='" + url + "'>Allocate</button>"; html += "<button class='btn btn-success btn-sm new-item-button' type='button' url='" + url + "'>Allocate Parts</button>";
html += "</div>"; html += "</div>";