From 9bd527c32f1fcc226d8eedcaef949984931e836c Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Tue, 13 Nov 2012 08:08:16 +0100 Subject: [PATCH] Remove assignments after end date for tasks marked as finished in the timesheets FEA: ItEr77S12AdaptPlanningAccordingTimesheets --- .../planner/entities/ResourceAllocation.java | 13 +++++++++++++ .../planner/adaptplanning/AdaptPlanningCommand.java | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java index b07c2529d..17f1d8378 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java @@ -2247,4 +2247,17 @@ public abstract class ResourceAllocation extends intendedResourcesPerDay = getNonConsolidatedResourcePerDay(); } + public void removeDayAssignmentsBeyondDate(LocalDate date) { + List toRemove = new ArrayList(); + + for (T t : getAssignments()) { + if (t.getDay().compareTo(date) >= 0) { + toRemove.add(t); + } + } + + setOnDayAssignmentRemoval(new DetachDayAssignmentOnRemoval()); + getDayAssignmentsState().removingAssignments(toRemove); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/adaptplanning/AdaptPlanningCommand.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/adaptplanning/AdaptPlanningCommand.java index 9a1783205..6276681ee 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/adaptplanning/AdaptPlanningCommand.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/adaptplanning/AdaptPlanningCommand.java @@ -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);