mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1871 from eeintech/stock_item_remove_redirect
Redirect to stock index if stock item is completely depleted
This commit is contained in:
commit
d6420341f4
@ -11,6 +11,7 @@ from django.views.generic import DetailView, ListView, UpdateView
|
||||
from django.forms.models import model_to_dict
|
||||
from django.forms import HiddenInput
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
@ -109,6 +110,22 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView):
|
||||
|
||||
return data
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
""" check if item exists else return to stock index """
|
||||
|
||||
stock_pk = kwargs.get('pk', None)
|
||||
|
||||
if stock_pk:
|
||||
try:
|
||||
stock_item = StockItem.objects.get(pk=stock_pk)
|
||||
except StockItem.DoesNotExist:
|
||||
stock_item = None
|
||||
|
||||
if not stock_item:
|
||||
return HttpResponseRedirect(reverse('stock-index'))
|
||||
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class StockItemNotes(InvenTreeRoleMixin, UpdateView):
|
||||
""" View for editing the 'notes' field of a StockItem object """
|
||||
|
Loading…
Reference in New Issue
Block a user