mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added views / forms to edit and delete BuildItem objects
- Alter stock allocation - remove (unallocate) stock from a build
This commit is contained in:
parent
24ed6f393b
commit
efbef251b6
3
InvenTree/build/templates/build/delete_build_item.html
Normal file
3
InvenTree/build/templates/build/delete_build_item.html
Normal file
@ -0,0 +1,3 @@
|
||||
Are you sure you want to unallocate these parts?
|
||||
<br>
|
||||
This will remove {{ item.quantity }} parts from build '{{ item.build.title }}'.
|
@ -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<pk>\d+)/', include(build_item_detail_urls)),
|
||||
url('^new/', views.BuildItemCreate.as_view(), name='build-item-create'),
|
||||
]
|
||||
|
||||
|
@ -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
|
||||
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',
|
||||
}
|
@ -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 += "<div class='btn-group' style='float: right;'>";
|
||||
|
||||
html += "<button class='btn btn-success btn-sm new-item-button' type='button' url='" + url + "'>Allocate</button>";
|
||||
@ -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 = "<button class='btn btn-success item-edit-button btn-sm' type='button' url='/build/item/" + row.pk + "/edit/'>Edit</button>";
|
||||
var bDel = "<button class='btn btn-danger item-del-button btn-sm' type='button' url='/build/item/" + row.pk + "/delete/'>Delete</button>";
|
||||
|
||||
html += "<div class='btn-group' style='float: right;'>" + bEdit + bDel + "</div>";
|
||||
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user