mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
commit
57e3fed2ea
@ -17,7 +17,6 @@ class PartCategory(InvenTreeTree):
|
|||||||
@property
|
@property
|
||||||
def parts(self):
|
def parts(self):
|
||||||
parts_list = self.part_set.all()
|
parts_list = self.part_set.all()
|
||||||
print(parts_list)
|
|
||||||
return parts_list
|
return parts_list
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import Warehouse, StockItem
|
from .models import StockLocation, StockItem
|
||||||
|
|
||||||
|
|
||||||
class WarehouseAdmin(admin.ModelAdmin):
|
class LocationAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'path', 'description')
|
list_display = ('name', 'path', 'description')
|
||||||
|
|
||||||
|
|
||||||
@ -11,5 +11,5 @@ class StockItemAdmin(admin.ModelAdmin):
|
|||||||
list_display = ('part', 'quantity', 'location', 'status', 'updated')
|
list_display = ('part', 'quantity', 'location', 'status', 'updated')
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Warehouse, WarehouseAdmin)
|
admin.site.register(StockLocation, LocationAdmin)
|
||||||
admin.site.register(StockItem, StockItemAdmin)
|
admin.site.register(StockItem, StockItemAdmin)
|
||||||
|
@ -6,15 +6,21 @@ from part.models import Part
|
|||||||
from InvenTree.models import InvenTreeTree
|
from InvenTree.models import InvenTreeTree
|
||||||
|
|
||||||
|
|
||||||
class Warehouse(InvenTreeTree):
|
class StockLocation(InvenTreeTree):
|
||||||
pass
|
""" Organization tree for StockItem objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def items(self):
|
||||||
|
stock_list = self.stockitem_set.all()
|
||||||
|
return stock_list
|
||||||
|
|
||||||
|
|
||||||
class StockItem(models.Model):
|
class StockItem(models.Model):
|
||||||
part = models.ForeignKey(Part,
|
part = models.ForeignKey(Part,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='locations')
|
related_name='locations')
|
||||||
location = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
|
location = models.ForeignKey(StockLocation, on_delete=models.CASCADE)
|
||||||
quantity = models.PositiveIntegerField()
|
quantity = models.PositiveIntegerField()
|
||||||
updated = models.DateField(auto_now=True)
|
updated = models.DateField(auto_now=True)
|
||||||
|
|
||||||
|
52
InvenTree/stock/serializers.py
Normal file
52
InvenTree/stock/serializers.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from .models import StockItem, StockLocation
|
||||||
|
|
||||||
|
|
||||||
|
class StockItemSerializer(serializers.ModelSerializer):
|
||||||
|
""" Serializer for a StockItem
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = StockItem
|
||||||
|
fields = ('pk',
|
||||||
|
'part',
|
||||||
|
'location',
|
||||||
|
'quantity',
|
||||||
|
'status',
|
||||||
|
'updated',
|
||||||
|
'last_checked',
|
||||||
|
'review_needed',
|
||||||
|
'expected_arrival')
|
||||||
|
|
||||||
|
|
||||||
|
class LocationBriefSerializer(serializers.ModelSerializer):
|
||||||
|
""" Brief information about a stock location
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = StockLocation
|
||||||
|
fields = ('pk',
|
||||||
|
'name',
|
||||||
|
'description')
|
||||||
|
|
||||||
|
|
||||||
|
class LocationDetailSerializer(serializers.ModelSerializer):
|
||||||
|
""" Detailed information about a stock location
|
||||||
|
"""
|
||||||
|
|
||||||
|
# List of all stock items in this location
|
||||||
|
items = StockItemSerializer(many=True)
|
||||||
|
|
||||||
|
# List of all child locations under this one
|
||||||
|
children = LocationBriefSerializer(many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = StockLocation
|
||||||
|
fields = ('pk',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'parent',
|
||||||
|
'path',
|
||||||
|
'children',
|
||||||
|
'items')
|
@ -3,5 +3,12 @@ from django.conf.urls import url
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.index, name='index')
|
# List all stock quantities for a given part
|
||||||
|
url(r'^part/(?P<part>[0-9]+)$', views.PartStockDetail.as_view()),
|
||||||
|
|
||||||
|
# List all stock items in a given location
|
||||||
|
url(r'^location/(?P<pk>[0-9]+)$', views.LocationDetail.as_view()),
|
||||||
|
|
||||||
|
# List all top-level locations
|
||||||
|
url(r'^location/$', views.LocationList.as_view())
|
||||||
]
|
]
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user