mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-05 21:20:56 +00:00
API for stock app
This commit is contained in:
@ -1,10 +1,33 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import generics
|
||||
|
||||
from .models import Warehouse
|
||||
from .models import StockLocation, StockItem
|
||||
|
||||
from .serializers import StockItemSerializer, LocationDetailSerializer
|
||||
|
||||
|
||||
def index(request):
|
||||
class PartStockDetail(generics.ListAPIView):
|
||||
""" Return a list of all stockitems for a given part
|
||||
"""
|
||||
|
||||
warehouses = Warehouse.objects.filter(parent=None)
|
||||
serializer_class = StockItemSerializer
|
||||
|
||||
return render(request, 'stock/index.html', {'warehouses': warehouses})
|
||||
def get_queryset(self):
|
||||
part_id = self.kwargs['part']
|
||||
return StockItem.objects.filter(part=part_id)
|
||||
|
||||
|
||||
class LocationDetail(generics.RetrieveAPIView):
|
||||
""" Return information on a specific stock location
|
||||
"""
|
||||
|
||||
queryset = StockLocation.objects.all()
|
||||
serializer_class = LocationDetailSerializer
|
||||
|
||||
|
||||
class LocationList(generics.ListAPIView):
|
||||
""" Return a list of top-level locations
|
||||
Locations are considered "top-level" if they do not have a parent
|
||||
"""
|
||||
|
||||
queryset = StockLocation.objects.filter(parent=None)
|
||||
serializer_class = LocationDetailSerializer
|
||||
|
Reference in New Issue
Block a user