diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py index d53956cbfb..5735a66f62 100644 --- a/InvenTree/build/api.py +++ b/InvenTree/build/api.py @@ -98,7 +98,7 @@ class BuildList(generics.ListCreateAPIView): as some of the fields don't natively play nicely with DRF """ - queryset = super().get_queryset().prefetch_related('part') + queryset = super().get_queryset().select_related('part') queryset = BuildSerializer.annotate_queryset(queryset) @@ -229,6 +229,15 @@ class BuildAllocate(generics.CreateAPIView): return context +class BuildItemDetail(generics.RetrieveUpdateDestroyAPIView): + """ + API endpoint for detail view of a BuildItem object + """ + + queryset = BuildItem.objects.all() + serializer_class = BuildItemSerializer + + class BuildItemList(generics.ListCreateAPIView): """ API endpoint for accessing a list of BuildItem objects @@ -258,9 +267,9 @@ class BuildItemList(generics.ListCreateAPIView): query = BuildItem.objects.all() - query = query.select_related('stock_item') - query = query.prefetch_related('stock_item__part') - query = query.prefetch_related('stock_item__part__category') + query = query.select_related('stock_item__location') + query = query.select_related('stock_item__part') + query = query.select_related('stock_item__part__category') return query @@ -330,12 +339,13 @@ build_api_urls = [ # Attachments url(r'^attachment/', include([ url(r'^(?P\d+)/', BuildAttachmentDetail.as_view(), name='api-build-attachment-detail'), - url('^.*$', BuildAttachmentList.as_view(), name='api-build-attachment-list'), + url(r'^.*$', BuildAttachmentList.as_view(), name='api-build-attachment-list'), ])), # Build Items url(r'^item/', include([ - url('^.*$', BuildItemList.as_view(), name='api-build-item-list') + url(r'^(?P\d+)/', BuildItemDetail.as_view(), name='api-build-item-detail'), + url(r'^.*$', BuildItemList.as_view(), name='api-build-item-list'), ])), # Build Detail diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index adbf7361eb..c15856d44e 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -256,22 +256,13 @@ class BuildAllocationSerializer(serializers.Serializer): return data def save(self): - print("creating new allocation items!") data = self.validated_data - print("data:") - print(data) - items = data.get('items', []) - print("items:") - print(items) - build = self.context['build'] - created_items = [] - with transaction.atomic(): for item in items: bom_item = item['bom_item'] @@ -288,10 +279,6 @@ class BuildAllocationSerializer(serializers.Serializer): install_into=output ) - created_items.append(build_item) - - return created_items - class BuildItemSerializer(InvenTreeModelSerializer): """ Serializes a BuildItem object """