Add order termination logic

This commit is contained in:
fnux 2020-05-08 09:31:46 +02:00
commit 89e853b490
2 changed files with 28 additions and 2 deletions

View file

@ -313,3 +313,15 @@ class AdminOrderViewSet(mixins.ListModelMixin,
def get_queryset(self):
return Order.objects.all()
@action(detail=True, methods=['post'])
def terminate(self, request, pk):
order = self.get_object()
if order.is_terminated:
return Response(
{'error': 'Order is already terminated.'},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
else:
order.terminate()
return Response({}, status=status.HTTP_200_OK)