Task duration not correct after recalculation

Hello,

We have been developing a solution involving the import and export MSProject data using Aspose tasks java. Because of the amount of data we are working with, we found that we had to disable automatic calculation to make the import and export viable. This isn’t a big problem, but it did introduce some issues that we were hoping could be fixed, or perhaps we are simply doing something incorrect leading to the problem. Either way your support would be appreciated.

It is important that task durations be the correct value when we export, for that reason we set the task duration even if we have already set a resource’s work. But we noticed some odd behavior when we disabled automatic calculation. I have provided some sandbox code used to reproduce the issue, along with all relevant files.

To begin, in this example we import the blank project, add some simple linked tasks, create a resource along with an assignment for each. For the second assignment, we set the units to 2.0 which should result in the overall duration being halved. Then once the data is set, we recalculate:

        Project project = new Project("filepath/TestBlankProject.mpp");

        project.setCalculationMode(CalculationMode.Manual);

        Task summaryTask = project.getRootTask().getChildren().add("Summary Task");
        Task childTask = summaryTask.getChildren().add("I am a child task");
        Task childTask2 = summaryTask.getChildren().add("I am another child task");

        project.getTaskLinks().add(childTask, childTask2);

        Resource testResource = project.getResources().add("Test Resource");
        // Just in case this was causing issues with units
        testResource.setMaxUnits(10);

        ResourceAssignment newAssignment = project.getResourceAssignments().add(childTask, testResource);
        ResourceAssignment newAssignment2 = project.getResourceAssignments().add(childTask2, testResource);

        newAssignment.setWork(project.getDuration(42, TimeUnitType.Hour));
        newAssignment2.setWork(project.getDuration(42, TimeUnitType.Hour));
        // Should reduce task duration to 21 hours
        newAssignment2.setUnits(2.0);

        childTask.setDuration(project.getDuration(42, TimeUnitType.Hour));
        childTask2.setDuration(project.getDuration(21, TimeUnitType.Hour));
        //Recalculate after setting task durations to what we expect
        project.recalculate();

        project.save("filepath/recalculateAfterSettingDuration.mpp");

Running this code results in both tasks having a duration of 42 hours. If you inspect the resource assignment on childTask2 you will see that the resource assignment data is correct, and in fact if you increase the units to 250%, press okay, then reduce it to 200% again and press okay you will see the duration reduce to 21 hours as we expected.

This behavior isn’t ideal for our application, so instead we attempted another solution where we instead recalculate before setting the duration values for the tasks:

        Project project = new Project("filepath/TestBlankProject.mpp");

        project.setCalculationMode(CalculationMode.Manual);

        Task summaryTask = project.getRootTask().getChildren().add("Summary Task");
        Task childTask = summaryTask.getChildren().add("I am a child task");
        Task childTask2 = summaryTask.getChildren().add("I am another child task");

        project.getTaskLinks().add(childTask, childTask2);

        Resource testResource = project.getResources().add("Test Resource");
        // Just in case this was causing issues with units
        testResource.setMaxUnits(10);

        ResourceAssignment newAssignment = project.getResourceAssignments().add(childTask, testResource);
        ResourceAssignment newAssignment2 = project.getResourceAssignments().add(childTask2, testResource);

        newAssignment.setWork(project.getDuration(42, TimeUnitType.Hour));
        newAssignment2.setWork(project.getDuration(42, TimeUnitType.Hour));
        // Should reduce task duration to 21 hours
        newAssignment2.setUnits(2.0);

        //Recalculate before setting task durations to what we expect
        project.recalculate();
        childTask.setDuration(project.getDuration(42, TimeUnitType.Hour));
        childTask2.setDuration(project.getDuration(21, TimeUnitType.Hour));

        project.save("filepath/recalculateBeforeSettingDuration.mpp");

Doing this fixes the issue of the second task’s duration being incorrect, but introduces a new issue. For some reason now the first task, childTask, has a completely incorrect duration of 8 hours. Again if you go into the task details and inspect the resource assignment, the data is correct. And if you change the work, press okay, then set it to the original value, the duration on the task becomes correct.

So with both options here we are encountering issues with having the tasks export with the proper durations. Is there some problem with how we are going about it? Is there any way to make a fix to one of these options so that all of the exported durations will be correct? Either by having units be calculated correctly or by having the duration on the child task set correctly after recalculating?

Note: here are the actual files for your inspection BugTest.zip (71.4 KB)

Thank you, and we hope to hear back!

@supportcec ,
we will investigate the attached code and will return with answer.

@supportcec
we found that project.recalculate() calculates assignmen’t finish date incorrectly.

The following new ticket was opened in our internal issue tracking system and we will deliver the fix according to the terms mentioned in Free Support Policies.

Issue ID(s): TASKSNET-11021

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.