[fix] validate with prev doc
diff --git a/setup/doctype/sales_person/test_sales_person.py b/setup/doctype/sales_person/test_sales_person.py
index 2dea3e5..f4283de 100644
--- a/setup/doctype/sales_person/test_sales_person.py
+++ b/setup/doctype/sales_person/test_sales_person.py
@@ -1,21 +1,25 @@
+test_dependencies = ["Employee"]
 test_records = [
 	[{
 		"doctype": "Sales Person",
 		"sales_person_name": "_Test Sales Person",
 		"parent_sales_person": "All Sales Persons",
-		"is_group": "No"
+		"is_group": "No",
+		"employee": "_T-Employee-0001",
 	}],
 	[{
 		"doctype": "Sales Person",
 		"sales_person_name": "_Test Sales Person 1",
 		"parent_sales_person": "All Sales Persons",
-		"is_group": "No"
+		"is_group": "No",
+		"employee": "_T-Employee-0002",
 	}],
 	[{
 		"doctype": "Sales Person",
 		"sales_person_name": "_Test Sales Person 2",
 		"parent_sales_person": "All Sales Persons",
-		"is_group": "No"
+		"is_group": "No",
+		"employee": "_T-Employee-0003",
 	}]
 	
 	
diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py
index 30a40da..74a75e6 100644
--- a/utilities/transaction_base.py
+++ b/utilities/transaction_base.py
@@ -301,23 +301,28 @@
 			
 	def validate_with_previous_doc(self, source_dt, ref):
 		for key, val in ref.items():
+			is_child = val.get("is_child_table")
 			ref_doc = {}
 			for d in self.doclist.get({"doctype": source_dt}):
-				if d.fields.get(val["ref_dn_field"]):
-					ref_doc.setdefault(key, d.fields[val["ref_dn_field"]])
-
-			if val.get("is_child_table"):
-				self.compare_values(ref_doc, val["compare_fields"], d)
-			else:
+				ref_dn = d.fields.get(val["ref_dn_field"])
+				if ref_dn:
+					if is_child:
+						self.compare_values({key: [ref_dn]}, val["compare_fields"], d)
+					elif ref_dn:								
+						ref_doc.setdefault(key, [])
+						if ref_dn not in ref_doc[key]:
+							ref_doc[key].append(ref_dn)
+			if ref_doc:
 				self.compare_values(ref_doc, val["compare_fields"])
 	
 	def compare_values(self, ref_doc, fields, doc=None):
-		for ref_doctype, ref_docname in ref_doc.items():
-			prevdoc_values = webnotes.conn.get_value(ref_doctype, ref_docname, 
-				[d[0] for d in fields], as_dict=1)
-			
-			for field, condition in fields:
-				self.validate_value(field, condition, prevdoc_values[field], doc)
+		for ref_doctype, ref_dn_list in ref_doc.items():
+			for ref_docname in ref_dn_list:
+				prevdoc_values = webnotes.conn.get_value(ref_doctype, ref_docname, 
+					[d[0] for d in fields], as_dict=1)
+
+				for field, condition in fields:
+					self.validate_value(field, condition, prevdoc_values[field], doc)
 
 def get_default_address_and_contact(party_field, party_name, fetch_shipping_address=False):
 	out = {}