diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java index ba21c7f15..484e2d712 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/OrderElement.java @@ -299,7 +299,7 @@ public abstract class OrderElement extends IntegrationEntity implements //we have to remove the TaskSource which contains a TaskGroup instead of TaskElement removeTaskSource(result); } - if(currentTaskSourceIsNotTheSame()) { + if (hadATaskSource() && currentTaskSourceIsNotTheSame()) { //this element was unscheduled and then scheduled again. Its TaskSource has //been recreated but we have to remove the old one. if(!getParent().currentTaskSourceIsNotTheSame()) { @@ -316,7 +316,7 @@ public abstract class OrderElement extends IntegrationEntity implements if (wasASchedulingPoint()) { result.add(taskSourceRemoval()); } - if(currentTaskSourceIsNotTheSame()) { + if (hadATaskSource() && currentTaskSourceIsNotTheSame()) { //all the children of this element were unscheduled and then scheduled again, //its TaskSource has been recreated but we have to remove the old one. if(getParent() == null || !getParent().currentTaskSourceIsNotTheSame()) { @@ -356,6 +356,10 @@ public abstract class OrderElement extends IntegrationEntity implements return getOnDBTaskSource() != getTaskSource(); } + protected boolean hadATaskSource() { + return getOnDBTaskSource() != null; + } + private List childrenSynchronizations() { List childrenOfGroup = new ArrayList(); for (OrderElement orderElement : getSomewhatScheduledOrderElements()) {