[Fix] Disallow same items to be fetched multiple times in sales invoice
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 39e87f8..c80d418 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -143,8 +143,35 @@
 			if(!cur_frm.doc.items[0].item_code) {
 				cur_frm.doc.items = cur_frm.doc.items.splice(1);
 			}
+
+			// find the doctype of the items table
+			var items_doctype = frappe.meta.get_docfield(cur_frm.doctype, 'items').options;
+			
+			// find the link fieldname from items table for the given
+			// source_doctype
+			var link_fieldname = null;
+			frappe.get_meta(items_doctype).fields.forEach(function(d) { 
+				if(d.options===opts.source_doctype) link_fieldname = d.fieldname; });
+
+			// search in existing items if the source_name is already set
+			var already_set = false;
+
+			$.each(cur_frm.doc.items, function(i, d) {
+				if(d[link_fieldname]==opts.source_name) {
+					already_set = true;
+					return false;
+				}
+			});
+
+			if(already_set) {
+				frappe.msgprint(__("You have already selected items from {0} {1}", 
+					[opts.source_doctype, opts.source_name]));
+				return;
+			}
+
 		}
 
+
 		return frappe.call({
 			// Sometimes we hit the limit for URL length of a GET request
 			// as we send the full target_doc. Hence this is a POST request.