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
|
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 = [
|
build_item_urls = [
|
||||||
|
url(r'^(?P<pk>\d+)/', include(build_item_detail_urls)),
|
||||||
url('^new/', views.BuildItemCreate.as_view(), name='build-item-create'),
|
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 stock.models import StockItem
|
||||||
from .forms import EditBuildForm, EditBuildItemForm
|
from .forms import EditBuildForm, EditBuildItemForm
|
||||||
|
|
||||||
from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView
|
from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView, AjaxDeleteView
|
||||||
|
|
||||||
|
|
||||||
class BuildIndex(ListView):
|
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):
|
class BuildItemCreate(AjaxCreateView):
|
||||||
""" View for allocating a new part to a build """
|
""" View for allocating a new part to a build """
|
||||||
|
|
||||||
@ -190,3 +206,17 @@ class BuildItemCreate(AjaxCreateView):
|
|||||||
pass
|
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',
|
field: 'sub_part_detail.name',
|
||||||
title: 'Part',
|
title: 'Part',
|
||||||
},
|
formatter: function(value, row, index, field) {
|
||||||
{
|
return renderLink(value, row.sub_part_detail.url);
|
||||||
field: 'note',
|
}
|
||||||
title: 'Note',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'quantity',
|
|
||||||
title: 'Required',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'allocated',
|
field: 'allocated',
|
||||||
title: 'Allocated',
|
title: 'Allocated to Build',
|
||||||
formatter: function(value, row, index, field) {
|
formatter: function(value, row, index, field) {
|
||||||
var html = "";
|
var html = "";
|
||||||
|
|
||||||
@ -63,6 +58,9 @@ function makeBuildTable(table, options) {
|
|||||||
html = "0";
|
html = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html += " of ";
|
||||||
|
html += row.quantity;
|
||||||
|
|
||||||
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</button>";
|
||||||
@ -140,15 +138,45 @@ function fillAllocationTable(table, index, parent_row, parent_table, options) {
|
|||||||
{
|
{
|
||||||
field: 'stock_item_detail.quantity',
|
field: 'stock_item_detail.quantity',
|
||||||
title: 'Available',
|
title: 'Available',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'quantity',
|
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,
|
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) {
|
table.on('load-success.bs.table', function(data) {
|
||||||
var allocated = 0;
|
var allocated = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user