From 1bc5fe26e256941e485c21ddf11d6a87fc57f59f Mon Sep 17 00:00:00 2001
From: Mario Raciti <mario.raciti@inaf.it>
Date: Thu, 13 May 2021 10:37:13 +0200
Subject: [PATCH] TMSS-519: Update scheduling_unit_draft/<id>/copy; fix issue
 in copy_scheduling_unit_draft

---
 SAS/TMSS/backend/src/tmss/tmssapp/tasks.py                  | 2 +-
 SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py | 6 +++---
 SAS/TMSS/backend/src/tmss/urls.py                           | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/tasks.py b/SAS/TMSS/backend/src/tmss/tmssapp/tasks.py
index b729f07ecdd..fcb0fd6d825 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/tasks.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/tasks.py
@@ -58,7 +58,7 @@ def copy_scheduling_unit_draft(scheduling_unit_draft: models.SchedulingUnitDraft
     task_drafts_copy = []
     scheduling_unit_draft_copy.save()
     for td in task_drafts:
-        task_drafts_copy.append(copy_task_draft(td))
+        task_drafts_copy.append(copy_task_draft(td, scheduling_unit_draft_copy.copy_reason))
     scheduling_unit_draft_copy.task_drafts.set(task_drafts_copy)
     scheduling_unit_draft_copy.save()
 
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py
index e2f0b0663b1..405fe4eebd4 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py
@@ -604,8 +604,8 @@ class SchedulingUnitDraftCopyViewSet(LOFARCopyViewSet):
                                     403: 'forbidden'},
                          operation_description="Copy a Scheduling Unit Draft to a new Scheduling Unit Draft")
     def create(self, request, *args, **kwargs):
-        if 'scheduling_unit_draft_id' in kwargs:
-            scheduling_unit_draft = get_object_or_404(models.SchedulingUnitDraft, pk=kwargs['scheduling_unit_draft_id'])
+        if 'id' in kwargs:
+            scheduling_unit_draft = get_object_or_404(models.SchedulingUnitDraft, pk=kwargs['id'])
             scheduling_set = scheduling_unit_draft.scheduling_set
 
             body_unicode = request.body.decode('utf-8')
@@ -639,7 +639,7 @@ class SchedulingUnitDraftCopyViewSet(LOFARCopyViewSet):
                             status=status.HTTP_201_CREATED,
                             headers={'Location': scheduling_unit_draft_copy_path})
         else:
-            content = {'Error': 'scheduling_unit_draft_id is missing'}
+            content = {'Error': 'SchedulingUnitDraft id is missing'}
             return Response(content, status=status.HTTP_404_NOT_FOUND)
 
 
diff --git a/SAS/TMSS/backend/src/tmss/urls.py b/SAS/TMSS/backend/src/tmss/urls.py
index 9d84e25fefe..e162afbba8b 100644
--- a/SAS/TMSS/backend/src/tmss/urls.py
+++ b/SAS/TMSS/backend/src/tmss/urls.py
@@ -186,7 +186,7 @@ router.register(r'task_blueprint/(?P<task_blueprint_id>\d+)/subtask', viewsets.S
 router.register(r'task_draft/(?P<task_draft_id>\d+)/copy', viewsets.TaskDraftCopyViewSet)
 router.register(r'task_blueprint/(?P<task_blueprint_id>\d+)/copy_to_task_draft', viewsets.TaskBlueprintCopyToTaskDraftViewSet)
 router.register(r'scheduling_set/(?P<scheduling_set_id>\d+)/copy_scheduling_unit_drafts', viewsets.SchedulingUnitDraftCopyFromSchedulingSetViewSet)
-router.register(r'scheduling_unit_draft/(?P<scheduling_unit_draft_id>\d+)/copy', viewsets.SchedulingUnitDraftCopyViewSet)
+router.register(r'scheduling_unit_draft/(?P<id>\d+)/copy', viewsets.SchedulingUnitDraftCopyViewSet)
 router.register(r'scheduling_unit_blueprint/(?P<scheduling_unit_blueprint_id>\d+)/copy_to_scheduling_unit_draft', viewsets.SchedulingUnitBlueprintCopyToSchedulingUnitDraftViewSet)
 
 
-- 
GitLab