追加任务bug

This commit is contained in:
caoqianming 2021-04-02 17:24:22 +08:00
parent f16bf41793
commit bafe8bbaed
1 changed files with 22 additions and 22 deletions

View File

@ -99,28 +99,28 @@ class TaskViewSet(CreateUpdateCustomMixin, ModelViewSet):
obj = self.get_object() obj = self.get_object()
depts = request.data['depts'] depts = request.data['depts']
contents = request.data['contents'] contents = request.data['contents']
if obj.state in ['待发布', '执行中']: if obj.state in ['待发布', '执行中']:
return Response('任务状态错误', status=status.HTTP_400_BAD_REQUEST) if depts and contents:
if depts and contents: for m in depts:
for m in depts: m = Organization.objects.get(pk=m)
m = Organization.objects.get(pk=m) TaskDept.objects.get_or_create(task=obj, dept=m, defaults={'task':obj, 'dept':m})
TaskDept.objects.get_or_create(task=obj, dept=m, defaults={'task':obj, 'dept':m}) for n in contents:
for n in contents: n = Content.objects.get(pk=n)
n = Content.objects.get(pk=n) if not Record.objects.filter(belong_dept=m, content=n, task=obj).exists():
if not Record.objects.filter(belong_dept=m, content=n, task=obj).exists(): r = Record()
r = Record() r.content = n
r.content = n r.content_name = n.name
r.content_name = n.name r.content_desc = n.desc
r.content_desc = n.desc r.belong_dept = m
r.belong_dept = m r.task = obj
r.task = obj r.end_date = obj.end_date
r.end_date = obj.end_date r.create_by = request.user
r.create_by = request.user r.state = '待上报'
r.state = '待上报' r.save()
r.save() obj.save()
obj.save() return Response(status=status.HTTP_200_OK)
return Response(status=status.HTTP_200_OK) return Response('单位或清单不能为空', status=status.HTTP_400_BAD_REQUEST)
return Response('单位或清单不能为空', status=status.HTTP_400_BAD_REQUEST) return Response('任务状态错误', status=status.HTTP_400_BAD_REQUEST)
@action(methods=['get'], detail=True, perms_map = {'get':'*'}) @action(methods=['get'], detail=True, perms_map = {'get':'*'})