Exposes BuildOrderAttachment objects to the REST API

This commit is contained in:
Oliver 2021-06-30 10:49:33 +10:00
parent f67779c816
commit a7d60cf5ad
2 changed files with 53 additions and 8 deletions

View File

@ -11,11 +11,12 @@ from rest_framework import generics
from django.conf.urls import url, include from django.conf.urls import url, include
from InvenTree.api import AttachmentMixin
from InvenTree.helpers import str2bool, isNull from InvenTree.helpers import str2bool, isNull
from InvenTree.status_codes import BuildStatus from InvenTree.status_codes import BuildStatus
from .models import Build, BuildItem from .models import Build, BuildItem, BuildOrderAttachment
from .serializers import BuildSerializer, BuildItemSerializer from .serializers import BuildAttachmentSerializer, BuildSerializer, BuildItemSerializer
class BuildList(generics.ListCreateAPIView): class BuildList(generics.ListCreateAPIView):
@ -226,14 +227,40 @@ class BuildItemList(generics.ListCreateAPIView):
] ]
build_item_api_urls = [ class BuildAttachmentList(generics.ListCreateAPIView, AttachmentMixin):
url('^.*$', BuildItemList.as_view(), name='api-build-item-list'), """
] API endpoint for listing (and creating) BuildOrderAttachment objects
"""
queryset = BuildOrderAttachment.objects.all()
serializer_class = BuildAttachmentSerializer
class BuildAttachmentDetail(generics.RetrieveUpdateDestroyAPIView, AttachmentMixin):
"""
Detail endpoint for a BuildOrderAttachment object
"""
queryset = BuildOrderAttachment.objects.all()
serializer_class = BuildAttachmentSerializer
build_api_urls = [ build_api_urls = [
url(r'^item/', include(build_item_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'),
])),
# Build Items
url(r'^item/', include([
url('^.*$', BuildItemList.as_view(), name='api-build-item-list')
])),
# Build Detail
url(r'^(?P<pk>\d+)/', BuildDetail.as_view(), name='api-build-detail'), url(r'^(?P<pk>\d+)/', BuildDetail.as_view(), name='api-build-detail'),
# Build List
url(r'^.*$', BuildList.as_view(), name='api-build-list'), url(r'^.*$', BuildList.as_view(), name='api-build-list'),
] ]

View File

@ -10,13 +10,13 @@ from django.db.models import BooleanField
from rest_framework import serializers from rest_framework import serializers
from InvenTree.serializers import InvenTreeModelSerializer from InvenTree.serializers import InvenTreeModelSerializer, InvenTreeAttachmentSerializerField
from stock.serializers import StockItemSerializerBrief from stock.serializers import StockItemSerializerBrief
from stock.serializers import LocationSerializer from stock.serializers import LocationSerializer
from part.serializers import PartSerializer, PartBriefSerializer from part.serializers import PartSerializer, PartBriefSerializer
from .models import Build, BuildItem from .models import Build, BuildItem, BuildOrderAttachment
class BuildSerializer(InvenTreeModelSerializer): class BuildSerializer(InvenTreeModelSerializer):
@ -143,3 +143,21 @@ class BuildItemSerializer(InvenTreeModelSerializer):
'stock_item_detail', 'stock_item_detail',
'quantity' 'quantity'
] ]
class BuildAttachmentSerializer(InvenTreeModelSerializer):
"""
Serializer for a BuildAttachment
"""
attachment = InvenTreeAttachmentSerializerField(required=True)
class Meta:
model = BuildOrderAttachment
fields = [
'pk',
'build',
'attachment',
'comment'
]