From a6f95c70aaf9049465438c68080a09603c54628f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 23 May 2019 21:36:54 +1000 Subject: [PATCH 1/2] Add detail view for Build model --- InvenTree/build/api.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py index 8e0a92917e..0ea90a00ba 100644 --- a/InvenTree/build/api.py +++ b/InvenTree/build/api.py @@ -40,6 +40,17 @@ class BuildList(generics.ListCreateAPIView): ] +class BuildDetail(generics.RetrieveUpdateAPIView): + """ API endpoint for detail view of a Build object """ + + queryset = Build.objects.all() + serializer_class = BuildSerializer + + permission_classes = [ + permissions.IsAuthenticatedOrReadOnly, + ] + + class BuildItemList(generics.ListCreateAPIView): """ API endpoint for accessing a list of BuildItem objects @@ -85,5 +96,7 @@ build_item_api_urls = [ build_api_urls = [ url(r'^item/?', include(build_item_api_urls)), + url(r'^(?P\d+)/', BuildDetail.as_view(), name='api-build-detail'), + url(r'^.*$', BuildList.as_view(), name='api-build-list'), ] From d386c2a6f9c33273b807777a575542bfda542d2f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 23 May 2019 21:51:27 +1000 Subject: [PATCH 2/2] Include total stock in PartBrief serializer --- InvenTree/part/models.py | 2 +- InvenTree/part/serializers.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 2cfb37d3e3..8383431caa 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -379,7 +379,7 @@ class Part(models.Model): total -= self.allocation_count - return total + return max(total, 0) def isStarredBy(self, user): """ Return True if this part has been starred by a particular user """ diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index cb7cc8bda3..15c82153b3 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -50,6 +50,7 @@ class PartBriefSerializer(serializers.ModelSerializer): 'url', 'full_name', 'description', + 'total_stock', 'available_stock', 'image_url', ]