From c6cae6e4552bcdb0938322da89c5976bca240b3e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 19 Nov 2021 11:05:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E9=97=B4=E6=93=8D=E4=BD=9C=E5=88=9B?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/views.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index 18f7577..b496ebd 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -270,6 +270,9 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Gen ordering_fields = ['id'] ordering = ['-id'] + def get_queryset(self): + return self.queryset.filter(create_by=self.request.user) + def get_serializer_class(self): if self.action == 'retrieve': return OperationDetailSerializer @@ -283,7 +286,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Gen serializer = OperationCreateSerializer(data=data, context={'request':self.request}) serializer.is_valid(raise_exception=True) vdata = serializer.validated_data #校验之后的数据 - step = Step.objects.get(pk=vdata['step']) + step = vdata['step'] op = Operation() op.step = step op.is_submited = False @@ -291,9 +294,8 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Gen # 创建操作所用半成品关联记录 if 'wproducts' in vdata: owps = [] - for i in vdata['wproducts']: + for wpd in vdata['wproducts']: owp = {} - wpd = WProduct.objects.get(pk=i) owp['operation'] = op owp['wproduct'] = wpd owp['number'] = wpd.number @@ -322,7 +324,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Gen -class OperationWproductViewSet(ListModelMixin, GenericViewSet): +class OperationWproductViewSet(ListModelMixin, DestroyModelMixin, GenericViewSet): """ 操作使用的半成品 """ @@ -333,6 +335,18 @@ class OperationWproductViewSet(ListModelMixin, GenericViewSet): ordering_fields = ['id'] ordering = ['-id'] + @transaction.atomic() + def destroy(self, request, *args, **kwargs): + instance = self.get_object() + if instance.operation.is_submited: + raise exceptions.APIException('该操作已提交') + instance.delete() + wp = instance.wproduct + wp.operation = None + wp.save() + return Response() + + class DoFormInit(CreateAPIView, GenericAPIView): perms_map={'*':'*'} serializer_class=OperationInitSerializer