Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/projects/doctype/time_log/time_log.js b/projects/doctype/time_log/time_log.js
index a602332..22f9610 100644
--- a/projects/doctype/time_log/time_log.js
+++ b/projects/doctype/time_log/time_log.js
@@ -1,5 +1,9 @@
-$.extend(cur_frm.cscript, {
-	refresh: function(doc) {
-		
+wn.provide("erpnext.projects");
+
+erpnext.projects.TimeLog = wn.ui.form.Controller.extend({
+	setup: function() {
+		this.frm.set_query("task", erpnext.queries.task);
 	}
-});
\ No newline at end of file
+});
+
+cur_frm.cscript = new erpnext.projects.TimeLog({frm: cur_frm});
\ No newline at end of file
diff --git a/projects/utils.py b/projects/utils.py
index 7a45b08..70f6995 100644
--- a/projects/utils.py
+++ b/projects/utils.py
@@ -5,4 +5,19 @@
 
 @webnotes.whitelist()
 def get_time_log_list(doctype, txt, searchfield, start, page_len, filters):
-	return webnotes.conn.get_values("Time Log", filters, ["name", "activity_type", "owner"])
\ No newline at end of file
+	return webnotes.conn.get_values("Time Log", filters, ["name", "activity_type", "owner"])
+
+@webnotes.whitelist()
+def query_task(doctype, txt, searchfield, start, page_len, filters):
+	search_string = "%%%s%%" % txt
+	order_by_string = "%s%%" % txt
+	return webnotes.conn.sql("""select name, subject from `tabTask`
+		where `%s` like %s or `subject` like %s 
+		order by
+			case when `subject` like %s then 0 else 1 end,
+			case when `%s` like %s then 0 else 1 end,
+			`%s`,
+			subject
+		limit %s, %s""" % 
+		(searchfield, "%s", "%s", "%s", searchfield, "%s", searchfield, "%s", "%s"),
+		(search_string, search_string, order_by_string, order_by_string, start, page_len))
\ No newline at end of file
diff --git a/public/js/queries.js b/public/js/queries.js
index 9809cd9..24ddc13 100644
--- a/public/js/queries.js
+++ b/public/js/queries.js
@@ -160,4 +160,8 @@
 			: "")
 		+ " LIMIT 50"
 
-}
\ No newline at end of file
+}
+
+erpnext.queries.task = function() {
+	return { query: "projects.utils.query_task" };
+};
\ No newline at end of file
diff --git a/selling/doctype/lead/lead.js b/selling/doctype/lead/lead.js
index d8d322d..118b4c7 100644
--- a/selling/doctype/lead/lead.js
+++ b/selling/doctype/lead/lead.js
@@ -104,7 +104,17 @@
 					'from_to_list':"[['Lead', 'Customer']]"
 				}, 
 				function(r,rt) {
-					loaddoc("Customer", n);
+					wn.model.with_doctype("Customer", function() {
+						var customer = wn.model.get_doc("Customer", n);
+						var customer_copy = $.extend({}, customer);
+
+						var updated = wn.model.set_default_values(customer_copy);
+						$.each(updated, function(i, f) {
+							if(!customer[f]) customer[f] = customer_copy[f];
+						});
+					
+						loaddoc("Customer", n);
+					});
 				}
 				);
 			}