mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add detail API endpoint for BuildItem model
This commit is contained in:
parent
5ded23fd99
commit
8f298f71ef
@ -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<pk>\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<pk>\d+)/', BuildItemDetail.as_view(), name='api-build-item-detail'),
|
||||
url(r'^.*$', BuildItemList.as_view(), name='api-build-item-list'),
|
||||
])),
|
||||
|
||||
# Build Detail
|
||||
|
@ -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 """
|
||||
|
Loading…
Reference in New Issue
Block a user