From 998ae94e7500b08ee5f4f61ca91e8306209b2bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Wed, 29 Sep 2010 15:32:14 +0200 Subject: [PATCH] Fix problem when adding extra hours at the end date of a partially completed date If you add extra hours to a partially completed last day and you quit the same extra hours to another day the resources per day count changes and this is confusing for the user. The implemented solution is to keep the same IntraDayDate end when modifying the last day. The real solution for the underlying would be to keep an spec object with the desired values from the user so when having to reallocate uses the original intention of the user and not the current resources per day and total hours values. FEA: ItEr61S05BugFixing --- .../planner/entities/ResourceAllocation.java | 7 ++-- .../AllocationUntilFillingHoursTest.java | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java index d89aafbb5..559b06955 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java @@ -721,15 +721,16 @@ public abstract class ResourceAllocation extends protected void resetAssigmentsForInterval(LocalDate startInclusive, LocalDate endExclusive, List assignmentsCreated) { - boolean finishedByEnd = isAlreadyFinishedBy(endExclusive); + boolean endMovedAfterCurrentEnd = getEndDate() != null + && getEndDate().compareTo(endExclusive) < 0; removingAssignments(withoutConsolidated(getAssignments(startInclusive, endExclusive))); addingAssignments(assignmentsCreated); updateOriginalTotalAssigment(); - updateResourcesPerDay(); - if (finishedByEnd) { + if (endMovedAfterCurrentEnd) { getDayAssignmentsState().setIntraDayEnd(null); } + updateResourcesPerDay(); } private static List withoutConsolidated( diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/AllocationUntilFillingHoursTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/AllocationUntilFillingHoursTest.java index 4568ce029..f78c96bd1 100644 --- a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/AllocationUntilFillingHoursTest.java +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/AllocationUntilFillingHoursTest.java @@ -122,6 +122,42 @@ public class AllocationUntilFillingHoursTest { equalTo(ResourcesPerDay.amount(1))); } + @Test + public void theResourcesPerDayAreKeptCorrectlyCalculatedAfterUpdatingTheEndInterval() { + final ResourcesPerDay oneResourcePerDay = ResourcesPerDay.amount(1); + givenSpecificAllocations(oneResourcePerDay); + ResourceAllocation.allocating(allocations).untilAllocating(30); + SpecificResourceAllocation allocation = (SpecificResourceAllocation) allocations + .get(0) + .getBeingModified(); + // hours per day: 8, 8, 8, 6 + allocation.onInterval(startDate, startDate.plusDays(1)) + .allocateHours(6); + // hours per day: 6, 8, 8, 6 + assertTrue(allocation.getResourcesPerDay().getAmount() + .compareTo(oneResourcePerDay.getAmount()) < 0); + + allocation.onInterval(startDate.plusDays(3), startDate.plusDays(4)) + .allocateHours(8); + // hours per day: 6, 8, 8, 8 + assertThat(allocation.getResourcesPerDay(), equalTo(oneResourcePerDay)); + // This last assertion is questionable. A solution would be to keep a + // Spec object at ResourceAllocation with the desired parameters from + // the user and then the real values. In the meantime doing an effort to + // keep the original value + + allocation.onInterval(startDate.plusDays(4), startDate.plusDays(5)) + .allocateHours(8); + // hours per day: 6, 8, 8, 8, 8 + assertTrue(allocation.getResourcesPerDay().getAmount() + .compareTo(oneResourcePerDay.getAmount()) < 0); + + // hours per day: 6, 8, 8, 8, 10 + allocation.onInterval(startDate.plusDays(4), startDate.plusDays(5)) + .allocateHours(10); + assertThat(allocation.getResourcesPerDay(), equalTo(oneResourcePerDay)); + } + @Test public void worksWellForSeveralSpecificAllocations() { givenSpecificAllocations(ResourcesPerDay.amount(1), ResourcesPerDay