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:
Oliver 2021-07-28 07:00:47 +10:00 committed by GitHub
commit d6420341f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 """