diff --git a/InvenTree/build/templates/build/delete_build_item.html b/InvenTree/build/templates/build/delete_build_item.html new file mode 100644 index 0000000000..23993feb95 --- /dev/null +++ b/InvenTree/build/templates/build/delete_build_item.html @@ -0,0 +1,3 @@ +Are you sure you want to unallocate these parts? +
+This will remove {{ item.quantity }} parts from build '{{ item.build.title }}'. \ No newline at end of file diff --git a/InvenTree/build/urls.py b/InvenTree/build/urls.py index ef7a1369f8..109616348d 100644 --- a/InvenTree/build/urls.py +++ b/InvenTree/build/urls.py @@ -6,7 +6,13 @@ from django.conf.urls import url, include from . import views +build_item_detail_urls = [ + url('^edit/?', views.BuildItemEdit.as_view(), name='build-item-edit'), + url('^delete/?', views.BuildItemDelete.as_view(), name='build-item-delete'), +] + build_item_urls = [ + url(r'^(?P\d+)/', include(build_item_detail_urls)), url('^new/', views.BuildItemCreate.as_view(), name='build-item-create'), ] diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 8e9fed0e90..ab2c7d9484 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -15,7 +15,7 @@ from .models import Build, BuildItem from stock.models import StockItem from .forms import EditBuildForm, EditBuildItemForm -from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView +from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView, AjaxDeleteView class BuildIndex(ListView): @@ -131,6 +131,22 @@ class BuildUpdate(AjaxUpdateView): } +class BuildItemDelete(AjaxDeleteView): + """ View to 'unallocate' a BuildItem. + Really we are deleting the BuildItem object from the database. + """ + + model = BuildItem + ajax_template_name = 'build/delete_build_item.html' + ajax_form_title = 'Unallocate Stock' + context_object_name = 'item' + + def get_data(self): + return { + 'danger': 'Removed parts from build allocation' + } + + class BuildItemCreate(AjaxCreateView): """ View for allocating a new part to a build """ @@ -189,4 +205,18 @@ class BuildItemCreate(AjaxCreateView): except Build.DoesNotExist: pass - return initials \ No newline at end of file + return initials + + +class BuildItemEdit(AjaxUpdateView): + """ View to edit a BuildItem object """ + + model = BuildItem + ajax_template_name = 'modal_form.html' + form_class = EditBuildItemForm + ajax_form_title = 'Edit Stock Allocation' + + def get_data(self): + return { + 'info': 'Updated Build Item', + } \ No newline at end of file diff --git a/InvenTree/static/script/inventree/build.js b/InvenTree/static/script/inventree/build.js index c644aa4061..cc6c611f85 100644 --- a/InvenTree/static/script/inventree/build.js +++ b/InvenTree/static/script/inventree/build.js @@ -38,18 +38,13 @@ function makeBuildTable(table, options) { { field: 'sub_part_detail.name', title: 'Part', - }, - { - field: 'note', - title: 'Note', - }, - { - field: 'quantity', - title: 'Required', + formatter: function(value, row, index, field) { + return renderLink(value, row.sub_part_detail.url); + } }, { field: 'allocated', - title: 'Allocated', + title: 'Allocated to Build', formatter: function(value, row, index, field) { var html = ""; @@ -63,6 +58,9 @@ function makeBuildTable(table, options) { html = "0"; } + html += " of "; + html += row.quantity; + html += "
"; html += ""; @@ -140,15 +138,45 @@ function fillAllocationTable(table, index, parent_row, parent_table, options) { { field: 'stock_item_detail.quantity', title: 'Available', - }, + }, { field: 'quantity', - title: 'Allocated' - }, + title: 'Allocated', + formatter: function(value, row, index, field) { + + var html = value; + + var bEdit = ""; + var bDel = ""; + + html += "
" + bEdit + bDel + "
"; + + return html; + } + } ], url: "/api/build/item?build=" + options.build + "&part=" + parent_row.sub_part, }); + // Button callbacks for editing and deleting the allocations + table.on('click', '.item-edit-button', function() { + var button = $(this); + + launchModalForm(button.attr('url'), { + success: function() { + } + }); + }); + + table.on('click', '.item-del-button', function() { + var button = $(this); + + launchDeleteForm(button.attr('url'), { + success: function() { + } + }); + }); + table.on('load-success.bs.table', function(data) { var allocated = 0;