2
0
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:
Oliver
2017-04-11 18:58:44 +10:00
parent 599cdc0a7b
commit 15582369d2
6 changed files with 100 additions and 13 deletions

View File

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