mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added /track/ API
This commit is contained in:
parent
37808f3834
commit
6f31e3447c
@ -17,13 +17,13 @@ def Inventree404(self):
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^stock/', include('stock.urls')),
|
||||
url(r'^part/', include('part.urls')),
|
||||
url(r'^supplier/', include('supplier.urls')),
|
||||
url(r'^track/', include('track.urls')),
|
||||
url(r'^project/', include('project.urls')),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||
url(r'^stock/?', include('stock.urls')),
|
||||
url(r'^part/?', include('part.urls')),
|
||||
url(r'^supplier/?', include('supplier.urls')),
|
||||
url(r'^track/?', include('track.urls')),
|
||||
url(r'^project/?', include('project.urls')),
|
||||
url(r'^admin/?', admin.site.urls),
|
||||
url(r'^auth/?', include('rest_framework.urls', namespace='rest_framework')),
|
||||
|
||||
# Any other URL
|
||||
url(r'', Inventree404)
|
||||
|
@ -57,7 +57,6 @@ class PartTrackingInfo(models.Model):
|
||||
a new PartTrackingInfo object should be created.
|
||||
"""
|
||||
|
||||
part = models.ForeignKey(UniquePart, on_delete=models.CASCADE)
|
||||
date = models.DateField(auto_now_add=True,
|
||||
editable=False)
|
||||
part = models.ForeignKey(UniquePart, on_delete=models.CASCADE, related_name='tracking_info')
|
||||
date = models.DateField(auto_now_add=True, editable=False)
|
||||
notes = models.CharField(max_length=500)
|
||||
|
27
InvenTree/track/serializers.py
Normal file
27
InvenTree/track/serializers.py
Normal file
@ -0,0 +1,27 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import UniquePart, PartTrackingInfo
|
||||
|
||||
|
||||
class UniquePartSerializer(serializers.ModelSerializer):
|
||||
|
||||
tracking_info = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = UniquePart
|
||||
fields = ['pk',
|
||||
'part',
|
||||
'revision',
|
||||
'creation_date',
|
||||
'serial',
|
||||
'createdBy',
|
||||
'customer',
|
||||
'status',
|
||||
'tracking_info']
|
||||
|
||||
|
||||
class PartTrackingInfoSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = PartTrackingInfo
|
||||
fields = '__all__'
|
@ -1,7 +1,19 @@
|
||||
from django.conf.urls import url
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index')
|
||||
infopatterns = [
|
||||
url(r'^(?P<pk>[0-9]+)/?$', views.PartTrackingDetail.as_view()),
|
||||
|
||||
url(r'^\?*[^/]*/?$', views.PartTrackingList.as_view())
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
url(r'info/?', include(infopatterns)),
|
||||
|
||||
# Detail for a single unique part
|
||||
url(r'^(?P<pk>[0-9]+)$', views.UniquePartDetail.as_view()),
|
||||
|
||||
# List all unique parts, with optional filters
|
||||
url(r'^\?*[^/]*/?$', views.UniquePartList.as_view()),
|
||||
]
|
||||
|
@ -1,5 +1,74 @@
|
||||
from django.http import HttpResponse
|
||||
import django_filters
|
||||
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
from .models import UniquePart, PartTrackingInfo
|
||||
from .serializers import UniquePartSerializer, PartTrackingInfoSerializer
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("This is the Tracking page")
|
||||
class UniquePartDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
|
||||
queryset = UniquePart.objects.all()
|
||||
serializer_class = UniquePartSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
|
||||
class UniquePartFilter(django_filters.rest_framework.FilterSet):
|
||||
# Filter based on serial number
|
||||
min_sn = django_filters.NumberFilter(name='serial', lookup_expr='gte')
|
||||
max_sn = django_filters.NumberFilter(name='serial', lookup_expr='lte')
|
||||
|
||||
class Meta:
|
||||
model = UniquePart
|
||||
fields = ['serial',]
|
||||
|
||||
class UniquePartList(generics.ListCreateAPIView):
|
||||
|
||||
serializer_class = UniquePartSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
|
||||
filter_class = UniquePartFilter
|
||||
|
||||
def get_queryset(self):
|
||||
parts = UniquePart.objects.all()
|
||||
query = self.request.query_params
|
||||
|
||||
# Filter by associated part
|
||||
part_id = query.get('part', None)
|
||||
if part_id:
|
||||
parts = parts.filter(part=part_id)
|
||||
|
||||
# Filter by serial number
|
||||
sn = query.get('sn', None)
|
||||
if sn:
|
||||
parts = parts.filter(serial=sn)
|
||||
|
||||
# Filter by customer
|
||||
customer = query.get('customer', None)
|
||||
if customer:
|
||||
parts = parts.filter(customer=customer)
|
||||
|
||||
return parts
|
||||
|
||||
|
||||
class PartTrackingDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
|
||||
queryset = PartTrackingInfo.objects.all()
|
||||
serializer_class = PartTrackingInfoSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
|
||||
class PartTrackingList(generics.ListCreateAPIView):
|
||||
|
||||
serializer_class = PartTrackingInfoSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
def get_queryset(self):
|
||||
tracking = PartTrackingInfo.objects.all()
|
||||
query = self.request.query_params
|
||||
|
||||
part_id = query.get('part', None)
|
||||
if part_id:
|
||||
tracking = tracking.filter(part=part_id)
|
||||
|
||||
return tracking
|
||||
|
Loading…
Reference in New Issue
Block a user