diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/Util.java b/libreplan-business/src/main/java/org/libreplan/business/common/Util.java index 769ad097a..fe8bbacfb 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/Util.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/Util.java @@ -27,6 +27,16 @@ import java.util.Collection; */ public class Util { + public static boolean equals(BaseEntity entity1, BaseEntity entity2) { + if (entity1 == null || entity2 == null) { + return false; + } + if (entity1.getId() == null || entity2.getId() == null) { + return false; + } + return entity1.getId().equals(entity2.getId()); + } + public static boolean contains(Collection collection, BaseEntity entity) { for (BaseEntity each : collection) { diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/workreports/IWorkReportModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/workreports/IWorkReportModel.java index 789507fd7..5c54666ea 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/workreports/IWorkReportModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/workreports/IWorkReportModel.java @@ -245,4 +245,10 @@ public interface IWorkReportModel extends IIntegrationEntityModel { WorkReportLine getFirstWorkReportLine(); + /** + * Checks if an {@link OrderElement} is finished or not in any + * {@link WorkReportLine} of this report or other report. + */ + boolean isFinished(OrderElement orderElement); + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/workreports/WorkReportCRUDController.java b/libreplan-webapp/src/main/java/org/libreplan/web/workreports/WorkReportCRUDController.java index 15ee26fe8..381161b04 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/workreports/WorkReportCRUDController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/workreports/WorkReportCRUDController.java @@ -1249,6 +1249,11 @@ public class WorkReportCRUDController extends GenericForwardComposer implements } }); + if (!line.isFinished() + && workReportModel.isFinished(line.getOrderElement())) { + finished.setDisabled(true); + } + row.appendChild(finished); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/workreports/WorkReportModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/workreports/WorkReportModel.java index 70de3ad76..048762e67 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/workreports/WorkReportModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/workreports/WorkReportModel.java @@ -34,6 +34,7 @@ import java.util.Set; import org.apache.commons.lang.Validate; import org.hibernate.Hibernate; import org.libreplan.business.common.IntegrationEntity; +import org.libreplan.business.common.Util; import org.libreplan.business.common.daos.IConfigurationDAO; import org.libreplan.business.common.entities.EntityNameEnum; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -51,6 +52,7 @@ import org.libreplan.business.resources.daos.IWorkerDAO; import org.libreplan.business.resources.entities.Resource; import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.workreports.daos.IWorkReportDAO; +import org.libreplan.business.workreports.daos.IWorkReportLineDAO; import org.libreplan.business.workreports.daos.IWorkReportTypeDAO; import org.libreplan.business.workreports.entities.WorkReport; import org.libreplan.business.workreports.entities.WorkReportLabelTypeAssigment; @@ -86,6 +88,9 @@ public class WorkReportModel extends IntegrationEntityModel implements @Autowired private IWorkReportDAO workReportDAO; + @Autowired + private IWorkReportLineDAO workReportLineDAO; + @Autowired private IOrderElementDAO orderElementDAO; @@ -653,4 +658,25 @@ public class WorkReportModel extends IntegrationEntityModel implements return workReport.getWorkReportLines().iterator().next(); } + @Override + @Transactional(readOnly = true) + public boolean isFinished(OrderElement orderElement) { + for (WorkReportLine line : workReport.getWorkReportLines()) { + if (line.isFinished() + && Util.equals(line.getOrderElement(), orderElement)) { + return true; + } + } + + List lines = workReportLineDAO + .findByOrderElementNotInWorkReportAnotherTransaction( + orderElement, workReport); + for (WorkReportLine line : lines) { + if (line.isFinished()) { + return true; + } + } + return false; + } + }