From e65e621145e3a5940ef58d025af3b5b3f79bad12 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 19 Nov 2012 15:43:18 +0530 Subject: [PATCH] get_query for profile based link fields to enable searching by name --- accounts/doctype/pos_setting/pos_setting.js | 2 ++ hr/doctype/employee/employee.js | 2 ++ public/build.json | 1 + public/js/startup.js | 2 +- public/js/utils.js | 26 +++++++++++++++++++ selling/doctype/lead/lead.js | 10 ++++++- selling/doctype/opportunity/opportunity.js | 6 ++++- selling/doctype/quotation/quotation.js | 6 ++++- .../authorization_rule/authorization_rule.js | 15 ++--------- .../doctype/communication/communication.js | 10 +++++++ .../doctype/support_ticket/support_ticket.js | 2 ++ 11 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 public/js/utils.js diff --git a/accounts/doctype/pos_setting/pos_setting.js b/accounts/doctype/pos_setting/pos_setting.js index a6e7247c9e1..237615bfe56 100755 --- a/accounts/doctype/pos_setting/pos_setting.js +++ b/accounts/doctype/pos_setting/pos_setting.js @@ -52,3 +52,5 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) { return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50'; } + +cur_frm.fields_dict.user.get_query = erpnext.utils.profile_query; \ No newline at end of file diff --git a/hr/doctype/employee/employee.js b/hr/doctype/employee/employee.js index 769e5b6d5d0..75866c50bde 100644 --- a/hr/doctype/employee/employee.js +++ b/hr/doctype/employee/employee.js @@ -64,3 +64,5 @@ cur_frm.cscript.make_salary_structure = function(doc,dt,dn,det){ st.grade=doc.grade; loaddoc('Salary Structure', st.name); } + +cur_frm.fields_dict.user_id.get_query = erpnext.utils.profile_query; \ No newline at end of file diff --git a/public/build.json b/public/build.json index bfad6074ece..2304ffb9f91 100644 --- a/public/build.json +++ b/public/build.json @@ -15,5 +15,6 @@ "app/public/js/themes.js", "app/public/js/toolbar.js", "app/public/js/feature_setup.js", + "app/public/js/utils.js" ], } \ No newline at end of file diff --git a/public/js/startup.js b/public/js/startup.js index 1757dc5d8ed..37cc75ea643 100644 --- a/public/js/startup.js +++ b/public/js/startup.js @@ -192,4 +192,4 @@ erpnext.setup_mousetrap = function() { // start $(document).bind('startup', function() { erpnext.startup.start(); -}); +}); \ No newline at end of file diff --git a/public/js/utils.js b/public/js/utils.js new file mode 100644 index 00000000000..76a443a56ae --- /dev/null +++ b/public/js/utils.js @@ -0,0 +1,26 @@ +// 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 . + +wn.provide('erpnext.utils'); + +// profile related get_query +erpnext.utils.profile_query = function() { + return "select name, concat_ws(' ', first_name, middle_name, last_name) \ + from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \ + name not in ('Administrator', 'Guest') and (%(key)s like \"%s\" or \ + concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \ + limit 50"; +}; \ No newline at end of file diff --git a/selling/doctype/lead/lead.js b/selling/doctype/lead/lead.js index 523ddd22af3..78182f21e47 100644 --- a/selling/doctype/lead/lead.js +++ b/selling/doctype/lead/lead.js @@ -43,6 +43,14 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { cur_frm.add_fetch('customer', 'customer_name', 'company_name'); cur_frm.cscript.make_communication_body(); + + if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) { + cur_frm.fields_dict.lead_owner.get_query = erpnext.utils.profile_query; + } + + if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) { + cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query; + } } cur_frm.cscript.refresh_custom_buttons = function(doc) { @@ -140,4 +148,4 @@ cur_frm.cscript['Create Opportunity'] = function(){ //get query select Territory cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50'; -} +} \ No newline at end of file diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index 17666ece0db..0d3d431fd5e 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -49,6 +49,10 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { } cur_frm.cscript.make_communication_body(); + + if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) { + cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query; + } } cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { @@ -204,4 +208,4 @@ cur_frm.cscript['Declare Opportunity Lost'] = function(){ //get query select Territory cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { - return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';} + return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';} \ No newline at end of file diff --git a/selling/doctype/quotation/quotation.js b/selling/doctype/quotation/quotation.js index cc5bc318adc..157ad7edd5e 100644 --- a/selling/doctype/quotation/quotation.js +++ b/selling/doctype/quotation/quotation.js @@ -50,6 +50,10 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { } } cur_frm.cscript.make_communication_body(); + + if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) { + cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query; + } } cur_frm.cscript.onload_post_render = function(doc, dt, dn) { @@ -337,4 +341,4 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) { doctype: 'Quotation' } cur_frm.cscript.notify(doc, args); -} +} \ No newline at end of file diff --git a/setup/doctype/authorization_rule/authorization_rule.js b/setup/doctype/authorization_rule/authorization_rule.js index 887835833b7..8bec206d152 100644 --- a/setup/doctype/authorization_rule/authorization_rule.js +++ b/setup/doctype/authorization_rule/authorization_rule.js @@ -85,12 +85,9 @@ cur_frm.cscript.transaction = function(doc,cdt,cdn){ } -// System User Trigger -// ------------------- -cur_frm.fields_dict['system_user'].get_query = function(doc) { - return 'SELECT tabProfile.name FROM tabProfile WHERE tabProfile.name not in ("Administrator","Guest") AND tabProfile.docstatus != 2 AND tabProfile.enabled = 1 AND tabProfile.%(key)s LIKE "%s" LIMIT 50' -} +cur_frm.fields_dict.system_user.get_query = erpnext.profile_query; +cur_frm.fields_dict.approving_user.get_query = erpnext.profile_query; // System Role Trigger // ----------------------- @@ -98,14 +95,6 @@ cur_frm.fields_dict['system_role'].get_query = function(doc) { return 'SELECT tabRole.name FROM tabRole WHERE tabRole.name not in ("Administrator","Guest","All") AND tabRole.%(key)s LIKE "%s" LIMIT 50' } - -// Approving User Trigger -// ----------------------- -cur_frm.fields_dict['approving_user'].get_query = function(doc) { - return 'SELECT tabProfile.name FROM tabProfile WHERE tabProfile.name not in ("Administrator","Guest") AND tabProfile.docstatus != 2 AND tabProfile.enabled = 1 AND tabProfile.%(key)s LIKE "%s" LIMIT 50' -} - - // Approving Role Trigger // ----------------------- cur_frm.fields_dict['approving_role'].get_query = function(doc) { diff --git a/support/doctype/communication/communication.js b/support/doctype/communication/communication.js index af92710bbd0..6f9147ead65 100644 --- a/support/doctype/communication/communication.js +++ b/support/doctype/communication/communication.js @@ -1,3 +1,13 @@ +cur_frm.cscript.onload = function(doc) { + cur_frm.fields_dict.user.get_query = function() { + return "select name, concat_ws(' ', first_name, middle_name, last_name) \ + from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \ + (%(key)s like \"%s\" or \ + concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \ + limit 50"; + }; +} + cur_frm.cscript.refresh = function(doc, dt, dn) { if(!doc.__islocal) { var field_list = ['lead', 'customer', 'supplier', 'contact', 'opportunity', diff --git a/support/doctype/support_ticket/support_ticket.js b/support/doctype/support_ticket/support_ticket.js index c08203136ab..3839b3b4d66 100644 --- a/support/doctype/support_ticket/support_ticket.js +++ b/support/doctype/support_ticket/support_ticket.js @@ -188,3 +188,5 @@ EmailMessage = function(parent, args, list, idx) { } this.make(); } + +cur_frm.fields_dict.allocated_to.get_query = erpnext.profile_query; \ No newline at end of file