mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Select the "default" where we wish to uninstall parts
This commit is contained in:
parent
39cfe39172
commit
81ce284264
@ -149,7 +149,8 @@ $('#installed-table').inventreeTable({
|
|||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
'items[]': [pk],
|
'items[]': [pk],
|
||||||
}
|
},
|
||||||
|
reload: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -159,4 +160,25 @@ $('#installed-table').inventreeTable({
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#multi-item-uninstall').click(function() {
|
||||||
|
|
||||||
|
var selections = $('#installed-table').bootstrapTable('getSelections');
|
||||||
|
|
||||||
|
var items = [];
|
||||||
|
|
||||||
|
selections.forEach(function(item) {
|
||||||
|
items.push(item.pk);
|
||||||
|
});
|
||||||
|
|
||||||
|
launchModalForm(
|
||||||
|
"{% url 'stock-item-uninstall' %}",
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
'items[]': items,
|
||||||
|
},
|
||||||
|
reload: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -706,6 +706,36 @@ class StockItemUninstall(AjaxView, FormMixin):
|
|||||||
|
|
||||||
return self.stock_items
|
return self.stock_items
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
|
||||||
|
initials = super().get_initial().copy()
|
||||||
|
|
||||||
|
# Keep track of the current locations of stock items
|
||||||
|
current_locations = set()
|
||||||
|
|
||||||
|
# Keep track of the default locations for stock items
|
||||||
|
default_locations = set()
|
||||||
|
|
||||||
|
for item in self.stock_items:
|
||||||
|
|
||||||
|
if item.location:
|
||||||
|
current_locations.add(item.location)
|
||||||
|
|
||||||
|
if item.part.default_location:
|
||||||
|
default_locations.add(item.part.default_location)
|
||||||
|
|
||||||
|
if len(current_locations) == 1:
|
||||||
|
# If the selected stock items are currently in a single location,
|
||||||
|
# select that location as the destination.
|
||||||
|
initials['location'] = next(iter(current_locations))
|
||||||
|
elif len(current_locations) == 0:
|
||||||
|
# There are no current locations set
|
||||||
|
if len(default_locations) == 1:
|
||||||
|
# Select the single default location
|
||||||
|
initials['location'] = next(iter(default_locations))
|
||||||
|
|
||||||
|
return initials
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
""" Extract list of stock items, which are supplied as a list,
|
""" Extract list of stock items, which are supplied as a list,
|
||||||
@ -717,8 +747,6 @@ class StockItemUninstall(AjaxView, FormMixin):
|
|||||||
else:
|
else:
|
||||||
self.stock_items = []
|
self.stock_items = []
|
||||||
|
|
||||||
print("GET:", request.GET)
|
|
||||||
|
|
||||||
return self.renderJsonResponse(request, self.get_form())
|
return self.renderJsonResponse(request, self.get_form())
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
@ -731,7 +759,7 @@ class StockItemUninstall(AjaxView, FormMixin):
|
|||||||
|
|
||||||
for item in self.request.POST:
|
for item in self.request.POST:
|
||||||
if item.startswith('stock-item-'):
|
if item.startswith('stock-item-'):
|
||||||
pk = item.replace('stock-item', '')
|
pk = item.replace('stock-item-', '')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stock_item = StockItem.objects.get(pk=pk)
|
stock_item = StockItem.objects.get(pk=pk)
|
||||||
@ -741,9 +769,22 @@ class StockItemUninstall(AjaxView, FormMixin):
|
|||||||
|
|
||||||
self.stock_items = items
|
self.stock_items = items
|
||||||
|
|
||||||
|
# Assume the form is valid, until it isn't!
|
||||||
|
valid = True
|
||||||
|
|
||||||
confirmed = str2bool(request.POST.get('confirm'))
|
confirmed = str2bool(request.POST.get('confirm'))
|
||||||
|
|
||||||
valid = False
|
location = request.POST.get('location', None)
|
||||||
|
|
||||||
|
if location:
|
||||||
|
try:
|
||||||
|
location = StockLocation.objects.get(pk=location)
|
||||||
|
except (ValueError, StockLocation.DoesNotExist):
|
||||||
|
location = None
|
||||||
|
|
||||||
|
if not location:
|
||||||
|
# Location is required!
|
||||||
|
valid = False
|
||||||
|
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
|
|
||||||
@ -755,6 +796,13 @@ class StockItemUninstall(AjaxView, FormMixin):
|
|||||||
'form_valid': valid,
|
'form_valid': valid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if valid:
|
||||||
|
# Ok, now let's actually uninstall the stock items
|
||||||
|
for item in self.stock_items:
|
||||||
|
pass
|
||||||
|
|
||||||
|
data['success'] = _('Uninstalled stock items')
|
||||||
|
|
||||||
return self.renderJsonResponse(request, form=form, data=data)
|
return self.renderJsonResponse(request, form=form, data=data)
|
||||||
|
|
||||||
def get_context_data(self):
|
def get_context_data(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user