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
This commit is contained in:
Óscar González Fernández 2010-09-29 15:32:14 +02:00
parent 7ee29c0da5
commit 998ae94e75
2 changed files with 40 additions and 3 deletions

View file

@ -721,15 +721,16 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
protected void resetAssigmentsForInterval(LocalDate startInclusive,
LocalDate endExclusive, List<T> 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 <T extends DayAssignment> List<T> withoutConsolidated(

View file

@ -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