// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

cur_frm.fields_dict['project'].get_query = function(doc,cdt,cdn){
  var cond='';
  if(doc.customer) cond = 'ifnull(`tabProject`.customer, "") = "'+doc.customer+'" AND';  
  return repl('SELECT distinct `tabProject`.`name` FROM `tabProject` \
  	WHERE %(cond)s `tabProject`.`name` LIKE "%s" \
	ORDER BY `tabProject`.`name` ASC LIMIT 50', {cond:cond});
}


cur_frm.cscript.project = function(doc, cdt, cdn){
  if(doc.project) get_server_fields('get_project_details', '','', doc, cdt, cdn, 1);
}

@@ -751,388 +751,303 @@
 %3E.%0A%0A
-cur_frm.fields_dict%5B'project'%5D.get_query = function(doc,cdt,cdn)%7B%0A  var cond='';%0A  if(doc.customer) cond = 'ifnull(%60tabProject%60.customer, %22%22) = %22'+doc.customer+'%22 AND';  %0A  return repl('SELECT distinct %60tabProject%60.%60name%60 FROM %60tabProject%60 %5C%0A  %09WHERE %25(cond)s %60tabProject%60.%60name%60 LIKE 
+wn.provide(%22erpnext.projects%22);%0A%0Aerpnext.projects.Task = erpnext.utils.Controller.extend(%7B%0A%09setup: function() %7B%0A%09%09this.frm.fields_dict.project.get_query = function() %7B%0A%09%09%09return %22select name from %60tabProject%60 %5C%0A%09%09%09%09where %25(key)s like %5C
 %22%25s
+%5C
 %22 %5C%0A%09
-ORDER BY %60tabProject%60.%60name%60 ASC LIMIT 50', %7Bcond:cond%7D);%0A%7D%0A%0A%0Acur_frm.cscript.
+%09%09%09order by name asc limit 50%22;%0A%09%09%7D;%0A%09%7D,%0A%0A%09
 project
- =
+:
  fun
@@ -1056,29 +1056,26 @@
 ion(
-doc, cdt, cdn)%7B%0A  if(
+) %7B%0A%09%09if(this.frm.
 doc.
@@ -1083,16 +1083,21 @@
 roject) 
+%7B%0A%09%09%09
 get_serv
@@ -1155,10 +1155,206 @@
 dn, 1);%0A
-%7D
+%09%09%7D%0A%09%7D,%0A%0A%09after_save: function() %7B%0A%09%09this.frm.doc.project && wn.model.remove_from_locals(%22Project%22,%0A%09%09%09this.frm.doc.project);%0A%09%7D,%0A%7D);%0A%0A%0Acur_frm.cscript = new erpnext.projects.Task(%7Bfrm: cur_frm%7D);%0A
 %0A

clear project from locals once task is saved