diff --git a/src/API/TimesheetController.php b/src/API/TimesheetController.php index 68f3a0d8..4acde9df 100644 --- a/src/API/TimesheetController.php +++ b/src/API/TimesheetController.php @@ -660,7 +660,6 @@ class TimesheetController extends BaseApiController ->setActivity($timesheet->getActivity()) ->setProject($timesheet->getProject()) ; - $this->service->prepareNewTimesheet($copyTimesheet); if (null !== ($copy = $paramFetcher->get('copy'))) { if (\in_array($copy, ['rates', 'all'])) { @@ -686,6 +685,12 @@ class TimesheetController extends BaseApiController } } + // needs to be executed AFTER copying the values! + // the event triggered in prepareNewTimesheet() will add meta fields first. Afterwards + // setMetaField() will merge meta fields and if we merge in the existing ones from the copied record, + // it will fail, because they do not have a type assigned + $this->service->prepareNewTimesheet($copyTimesheet); + $this->service->restartTimesheet($copyTimesheet, $timesheet); $view = new View($copyTimesheet, 200);