Remove assignments after end date for tasks marked as finished in the timesheets

FEA: ItEr77S12AdaptPlanningAccordingTimesheets
This commit is contained in:
Manuel Rego Casasnovas 2012-11-13 08:08:16 +01:00
parent b8f17c7235
commit 9bd527c32f
2 changed files with 25 additions and 0 deletions

View file

@ -2247,4 +2247,17 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
intendedResourcesPerDay = getNonConsolidatedResourcePerDay();
}
public void removeDayAssignmentsBeyondDate(LocalDate date) {
List<T> toRemove = new ArrayList<T>();
for (T t : getAssignments()) {
if (t.getDay().compareTo(date) >= 0) {
toRemove.add(t);
}
}
setOnDayAssignmentRemoval(new DetachDayAssignmentOnRemoval());
getDayAssignmentsState().removingAssignments(toRemove);
}
}

View file

@ -22,6 +22,7 @@ import static org.libreplan.web.I18nHelper._;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.joda.time.LocalDate;
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
@ -32,6 +33,7 @@ import org.libreplan.business.advance.exceptions.DuplicateAdvanceAssignmentForOr
import org.libreplan.business.advance.exceptions.DuplicateValueTrueReportGlobalAdvanceException;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.planner.entities.PositionConstraintType;
import org.libreplan.business.planner.entities.ResourceAllocation;
import org.libreplan.business.planner.entities.Task;
import org.libreplan.business.planner.entities.TaskElement;
import org.libreplan.business.workingday.IntraDayDate;
@ -77,6 +79,7 @@ public class AdaptPlanningCommand implements IAdaptPlanningCommand {
if (orderElement.isFinishedTimesheets()) {
setEndDate(taskElement, lastTimesheetDate);
addTimesheetsProgress(orderElement, lastTimesheetDate);
removeResourceAllocationsBeyondEndDate(taskElement);
} else {
removeTimesheetsProgressIfAny(orderElement);
}
@ -88,6 +91,15 @@ public class AdaptPlanningCommand implements IAdaptPlanningCommand {
context.reloadCharts();
}
private void removeResourceAllocationsBeyondEndDate(TaskElement taskElement) {
LocalDate endDate = taskElement.getEndAsLocalDate();
for (ResourceAllocation<?> resourceAllocation : taskElement
.getAllResourceAllocations()) {
resourceAllocation.removeDayAssignmentsBeyondDate(endDate);
}
}
private void setStartDateAndConstraint(TaskElement taskElement,
Date startDate) {
taskElement.setStartDate(startDate);