车间操作创建
This commit is contained in:
parent
718845b39a
commit
c6cae6e455
|
@ -270,6 +270,9 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Gen
|
||||||
ordering_fields = ['id']
|
ordering_fields = ['id']
|
||||||
ordering = ['-id']
|
ordering = ['-id']
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return self.queryset.filter(create_by=self.request.user)
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
if self.action == 'retrieve':
|
if self.action == 'retrieve':
|
||||||
return OperationDetailSerializer
|
return OperationDetailSerializer
|
||||||
|
@ -283,7 +286,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Gen
|
||||||
serializer = OperationCreateSerializer(data=data, context={'request':self.request})
|
serializer = OperationCreateSerializer(data=data, context={'request':self.request})
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
vdata = serializer.validated_data #校验之后的数据
|
vdata = serializer.validated_data #校验之后的数据
|
||||||
step = Step.objects.get(pk=vdata['step'])
|
step = vdata['step']
|
||||||
op = Operation()
|
op = Operation()
|
||||||
op.step = step
|
op.step = step
|
||||||
op.is_submited = False
|
op.is_submited = False
|
||||||
|
@ -291,9 +294,8 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Gen
|
||||||
# 创建操作所用半成品关联记录
|
# 创建操作所用半成品关联记录
|
||||||
if 'wproducts' in vdata:
|
if 'wproducts' in vdata:
|
||||||
owps = []
|
owps = []
|
||||||
for i in vdata['wproducts']:
|
for wpd in vdata['wproducts']:
|
||||||
owp = {}
|
owp = {}
|
||||||
wpd = WProduct.objects.get(pk=i)
|
|
||||||
owp['operation'] = op
|
owp['operation'] = op
|
||||||
owp['wproduct'] = wpd
|
owp['wproduct'] = wpd
|
||||||
owp['number'] = wpd.number
|
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_fields = ['id']
|
||||||
ordering = ['-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):
|
class DoFormInit(CreateAPIView, GenericAPIView):
|
||||||
perms_map={'*':'*'}
|
perms_map={'*':'*'}
|
||||||
serializer_class=OperationInitSerializer
|
serializer_class=OperationInitSerializer
|
||||||
|
|
Loading…
Reference in New Issue