2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 13:10:57 +00:00

Allow build orders to be deleted via the API (#3155)

This commit is contained in:
Oliver
2022-06-08 07:45:42 +10:00
committed by GitHub
parent 403655e3d2
commit a816c14b95
6 changed files with 56 additions and 27 deletions

View File

@ -1,8 +1,10 @@
"""JSON API for the Build app."""
from django.urls import include, re_path
from django.utils.translation import gettext_lazy as _
from rest_framework import filters, generics
from rest_framework.exceptions import ValidationError
from django_filters.rest_framework import DjangoFilterBackend
from django_filters import rest_framework as rest_filters
@ -198,12 +200,24 @@ class BuildList(APIDownloadMixin, generics.ListCreateAPIView):
return self.serializer_class(*args, **kwargs)
class BuildDetail(generics.RetrieveUpdateAPIView):
class BuildDetail(generics.RetrieveUpdateDestroyAPIView):
"""API endpoint for detail view of a Build object."""
queryset = Build.objects.all()
serializer_class = build.serializers.BuildSerializer
def destroy(self, request, *args, **kwargs):
"""Only allow deletion of a BuildOrder if the build status is CANCELLED"""
build = self.get_object()
if build.status != BuildStatus.CANCELLED:
raise ValidationError({
"non_field_errors": [_("Build must be cancelled before it can be deleted")]
})
return super().destroy(request, *args, **kwargs)
class BuildUnallocate(generics.CreateAPIView):
"""API endpoint for unallocating stock items from a build order.