mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Skeleton code for Build cancel() and complete() functions
- BuildComplete view
This commit is contained in:
parent
d518739643
commit
fb89574c42
@ -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) """
|
||||
|
@ -12,6 +12,10 @@
|
||||
<table class='table table-striped' id='build-table'>
|
||||
</table>
|
||||
|
||||
<div>
|
||||
<button class='btn btn-warning' type='button' id='complete-build'>Complete Build</button>
|
||||
</div>
|
||||
|
||||
{% 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 %}
|
1
InvenTree/build/templates/build/complete.html
Normal file
1
InvenTree/build/templates/build/complete.html
Normal file
@ -0,0 +1 @@
|
||||
Mark as COMPLETE
|
@ -118,7 +118,7 @@
|
||||
launchModalForm("{% url 'build-cancel' build.id %}",
|
||||
{
|
||||
reload: true,
|
||||
submit_text: "Cancel",
|
||||
submit_text: "Cancel Build",
|
||||
});
|
||||
});
|
||||
{% endblock %}
|
||||
|
@ -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'),
|
||||
]
|
||||
|
@ -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
|
||||
|
@ -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 += "<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>";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user