From ef6b2d58d152647f6d0eff5262ff572a469ad0b4 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Thu, 21 May 2015 09:04:55 +0000
Subject: [PATCH] SSDM-1932 : Bugfix on children generator

SVN: 34018
---
 .../1/dss/reporting-plugins/newbrowserapi/script.py       | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/plasmid/source/core-plugins/eln-lims/1/dss/reporting-plugins/newbrowserapi/script.py b/plasmid/source/core-plugins/eln-lims/1/dss/reporting-plugins/newbrowserapi/script.py
index b4001db5bfd..847a7985473 100644
--- a/plasmid/source/core-plugins/eln-lims/1/dss/reporting-plugins/newbrowserapi/script.py
+++ b/plasmid/source/core-plugins/eln-lims/1/dss/reporting-plugins/newbrowserapi/script.py
@@ -395,9 +395,11 @@ def insertUpdateSample(tr, parameters, tableBuilder):
 		sample.setParentSampleIdentifiers(sampleParents);
 	
 	#Create new sample children
+	sampleChildrenNewIdentifiers = [];
 	if sampleChildrenNew != None:
 		for newSampleChild in sampleChildrenNew:
 			child = tr.createNewSample(newSampleChild["identifier"], newSampleChild["sampleTypeCode"]); #Create Sample given his id
+			sampleChildrenNewIdentifiers.append(newSampleChild["identifier"]);
 			child.setParentSampleIdentifiers([sampleIdentifier]);
 			for key in newSampleChild["properties"].keySet():
 				propertyValue = unicode(newSampleChild["properties"][key]);
@@ -406,11 +408,11 @@ def insertUpdateSample(tr, parameters, tableBuilder):
 				
 				child.setPropertyValue(key,propertyValue);
 		
-	#Add sample children
+	#Add sample children that are not newly created
 	if sampleChildren != None:
 		for sampleChildIdentifier in sampleChildren:
-			child = getSampleByIdentifierForUpdate(tr, sampleChildIdentifier); #Retrieve Sample
-			if child != None: #The new created ones will not be found
+			if sampleChildIdentifier not in sampleChildrenNewIdentifiers:
+				child = getSampleByIdentifierForUpdate(tr, sampleChildIdentifier); #Retrieve Sample
 				childParents = child.getParentSampleIdentifiers();
 				childParents.add(sampleIdentifier);
 				child.setParentSampleIdentifiers(childParents);
-- 
GitLab