From 93a35cab19b67d95c1f88a2cf726ee2b65e1feaa Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 21 Nov 2012 18:02:22 +0530 Subject: [PATCH] added customer get_query to allow search based on customer name. also don't show name again if id naming is based on customer name and not series --- accounts/doctype/c_form/c_form.js | 4 ++- .../production_planning_tool.js | 5 +++ projects/doctype/project/project.js | 4 ++- projects/doctype/task/task.js | 2 ++ projects/doctype/task/task.py | 3 +- projects/doctype/timesheet/timesheet.js | 5 ++- public/js/account_tree_grid.js | 2 +- public/js/utils.js | 32 +++++++++++++++++++ .../installation_note/installation_note.js | 1 + selling/doctype/lead/lead.js | 4 ++- selling/doctype/opportunity/opportunity.js | 4 ++- selling/doctype/sales_common/sales_common.js | 2 ++ .../shipping_address/shipping_address.js | 2 ++ stock/doctype/bin/bin.py | 2 +- stock/doctype/delivery_note/delivery_note.js | 2 +- stock/doctype/item/item.js | 5 ++- stock/doctype/serial_no/serial_no.js | 4 ++- stock/doctype/stock_entry/stock_entry.js | 2 ++ .../doctype/communication/communication.js | 4 ++- .../doctype/customer_issue/customer_issue.js | 2 ++ .../maintenance_schedule.js | 2 ++ .../maintenance_visit/maintenance_visit.js | 2 ++ .../doctype/support_ticket/support_ticket.js | 4 ++- .../doctype/support_ticket/support_ticket.py | 2 +- utilities/doctype/address/address.js | 2 +- utilities/doctype/contact/contact.js | 2 +- 26 files changed, 89 insertions(+), 16 deletions(-) diff --git a/accounts/doctype/c_form/c_form.js b/accounts/doctype/c_form/c_form.js index d9e5c68d2b..adb989d8f7 100644 --- a/accounts/doctype/c_form/c_form.js +++ b/accounts/doctype/c_form/c_form.js @@ -26,4 +26,6 @@ cur_frm.fields_dict.invoice_details.grid.get_field("invoice_no").get_query = fun cur_frm.cscript.invoice_no = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; get_server_fields('get_invoice_details', d.invoice_no, 'invoice_details', doc, cdt, cdn, 1); -} \ No newline at end of file +} + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/production/doctype/production_planning_tool/production_planning_tool.js b/production/doctype/production_planning_tool/production_planning_tool.js index 11d6e44c10..9caf829127 100644 --- a/production/doctype/production_planning_tool/production_planning_tool.js +++ b/production/doctype/production_planning_tool/production_planning_tool.js @@ -48,3 +48,8 @@ cur_frm.fields_dict['pp_details'].grid.get_field('bom_no').get_query = function( var d = locals[this.doctype][this.docname]; return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = "Yes" AND `tabBOM`.docstatus = 1 AND `tabBOM`.`name` like "%s" ORDER BY `tabBOM`.`name` LIMIT 50'; } + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; + +cur_frm.fields_dict.pp_so_details.grid.get_field("customer").get_query = + erpnext.utils.customer_query; \ No newline at end of file diff --git a/projects/doctype/project/project.js b/projects/doctype/project/project.js index 560544152d..7f847b97f8 100644 --- a/projects/doctype/project/project.js +++ b/projects/doctype/project/project.js @@ -27,4 +27,6 @@ cur_frm.cscript.refresh = function(doc) { cur_frm.gantt_area.empty(); erpnext.show_task_gantt(cur_frm.gantt_area, cur_frm.docname); } -} \ No newline at end of file +} + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/projects/doctype/task/task.js b/projects/doctype/task/task.js index 295c58eb93..18c16538ca 100644 --- a/projects/doctype/task/task.js +++ b/projects/doctype/task/task.js @@ -27,6 +27,8 @@ cur_frm.cscript.project = function(doc, cdt, cdn){ if(doc.project) get_server_fields('get_project_details', '','', doc, cdt, cdn, 1); } + +// TODO: remove these? field doesn't exist, but custom field could exist cur_frm.fields_dict['customer'].get_query = function(doc,cdt,cdn){ var cond=''; if(doc.project) cond = 'ifnull(`tabProject`.customer, "") = `tabCustomer`.name AND ifnull(`tabProject`.name, "") = "'+doc.project+'" AND'; diff --git a/projects/doctype/task/task.py b/projects/doctype/task/task.py index 423d34307f..175379f78e 100644 --- a/projects/doctype/task/task.py +++ b/projects/doctype/task/task.py @@ -41,7 +41,8 @@ class DocType: if cust: ret = {'customer': cust and cust[0][0] or '', 'customer_name': cust and cust[0][1] or ''} return ret - + + # TODO: Remove these? as the field customer doesn't exists def get_customer_details(self): cust = sql("select customer_name from `tabCustomer` where name=%s", self.doc.customer) if cust: diff --git a/projects/doctype/timesheet/timesheet.js b/projects/doctype/timesheet/timesheet.js index 81f0420ec8..dc973fe149 100644 --- a/projects/doctype/timesheet/timesheet.js +++ b/projects/doctype/timesheet/timesheet.js @@ -44,4 +44,7 @@ cur_frm.fields_dict['timesheet_details'].grid.get_field("task_name").get_query = if(d.project_name) cond = 'ifnull(`tabTask`.project, "") = "'+d.project_name+'" AND'; return repl('SELECT distinct `tabTask`.`subject` FROM `tabTask` WHERE %(cond)s `tabTask`.`subject` LIKE "%s" ORDER BY `tabTask`.`subject` ASC LIMIT 50', {cond:cond}); -} \ No newline at end of file +} + +cur_frm.fields_dict.timesheet_details.grid.get_field("customer_name").get_query = + erpnext.utils.customer_query; \ No newline at end of file diff --git a/public/js/account_tree_grid.js b/public/js/account_tree_grid.js index cf33ee4f6d..10e1daccde 100644 --- a/public/js/account_tree_grid.js +++ b/public/js/account_tree_grid.js @@ -105,7 +105,7 @@ erpnext.AccountTreeGrid = wn.views.TreeGridReport.extend({ } me.init_account(d); - }); + }); } this.set_indent(); this.prepare_balances(); diff --git a/public/js/utils.js b/public/js/utils.js index 185baa6e29..4398498820 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -51,3 +51,35 @@ erpnext.utils.lead_query = function() { case when company_name like \"%s%%\" then 0 else 1 end, \ lead_name asc limit 50"; }; + +// searches for customer +erpnext.utils.customer_query = function() { + if(sys_defaults.cust_master_name == "Customer Name") { + var fields = ["name", "customer_group", "country", "territory"]; + } else { + var fields = ["name", "customer_name", "customer_group", "country", "territory"]; + } + + return "select " + fields.join(", ") + " from `tabCustomer` where docstatus < 2 and \ + (%(key)s like \"%s\" or customer_name like \"%%%s\") \ + order by \ + case when name like \"%s%%\" then 0 else 1 end, \ + case when customer_name like \"%s%%\" then 0 else 1 end, \ + name, customer_name limit 50"; +}; + +// searches for supplier +erpnext.utils.supplier_query = function() { + if(sys_defaults.supp_master_name == "Supplier Name") { + var fields = ["name", "supplier_type"]; + } else { + var fields = ["name", "supplier_name", "supplier_type"]; + } + + return "select " + fields.join(", ") + " from `tabSupplier` where docstatus < 2 and \ + (%(key)s like \"%s\" or supplier_name like \"%%%s\") \ + order by \ + case when name like \"%s%%\" then 0 else 1 end, \ + case when supplier_name like \"%s%%\" then 0 else 1 end, \ + name, supplier_name limit 50"; +}; \ No newline at end of file diff --git a/selling/doctype/installation_note/installation_note.js b/selling/doctype/installation_note/installation_note.js index 44f6ac8bf9..f298eda2fb 100644 --- a/selling/doctype/installation_note/installation_note.js +++ b/selling/doctype/installation_note/installation_note.js @@ -83,3 +83,4 @@ cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; } +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/selling/doctype/lead/lead.js b/selling/doctype/lead/lead.js index 78182f21e4..8c940bcf81 100644 --- a/selling/doctype/lead/lead.js +++ b/selling/doctype/lead/lead.js @@ -148,4 +148,6 @@ 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 +} + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index 4070f5e9dc..a7290928d7 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -210,4 +210,6 @@ cur_frm.cscript['Declare Opportunity Lost'] = function(){ 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';} -cur_frm.fields_dict.lead.get_query = erpnext.utils.lead_query; \ No newline at end of file +cur_frm.fields_dict.lead.get_query = erpnext.utils.lead_query; + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index be6f3f1301..65112b5ca4 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -857,3 +857,5 @@ cur_frm.cscript.validate_items = function(doc) { validated = false; } } + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/selling/doctype/shipping_address/shipping_address.js b/selling/doctype/shipping_address/shipping_address.js index 0ac173a6cc..deea4ed445 100755 --- a/selling/doctype/shipping_address/shipping_address.js +++ b/selling/doctype/shipping_address/shipping_address.js @@ -18,3 +18,5 @@ // ===================================================================== cur_frm.add_fetch('customer','customer_name','customer_name'); cur_frm.add_fetch('customer','address','customer_address'); + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/stock/doctype/bin/bin.py b/stock/doctype/bin/bin.py index 2f78f9c2fe..fdf9eeb9a3 100644 --- a/stock/doctype/bin/bin.py +++ b/stock/doctype/bin/bin.py @@ -273,7 +273,7 @@ class DocType: self.exc_list = [] for sle in sll: # block if stock level goes negative on any date - if val_method != 'Moving Average' or flt(allow_negative_stock) == 0: + if (val_method != 'Moving Average') or (cint(allow_negative_stock) == 0): if self.validate_negative_stock(cqty, sle): cqty += sle['actual_qty'] continue diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js index e1f8b3784e..4a3910abec 100644 --- a/stock/doctype/delivery_note/delivery_note.js +++ b/stock/doctype/delivery_note/delivery_note.js @@ -332,4 +332,4 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) { doctype: 'Delivery Note' } cur_frm.cscript.notify(doc, args); -} +} \ No newline at end of file diff --git a/stock/doctype/item/item.js b/stock/doctype/item/item.js index 332a3f093e..c5501d5166 100644 --- a/stock/doctype/item/item.js +++ b/stock/doctype/item/item.js @@ -141,4 +141,7 @@ cur_frm.cscript.validate = function(doc,cdt,cdn){ cur_frm.fields_dict['ref_rate_details'].grid.onrowadd = function(doc, cdt, cdn){ locals[cdt][cdn].ref_currency = sys_defaults.currency; refresh_field('ref_currency',cdn,'ref_rate_details'); -} \ No newline at end of file +} + +cur_frm.fields_dict.item_customer_details.grid.get_field("customer_name").get_query = + erpnext.utils.customer_query; \ No newline at end of file diff --git a/stock/doctype/serial_no/serial_no.js b/stock/doctype/serial_no/serial_no.js index 901acd2e7d..62a912670d 100644 --- a/stock/doctype/serial_no/serial_no.js +++ b/stock/doctype/serial_no/serial_no.js @@ -67,4 +67,6 @@ cur_frm.fields_dict['item_code'].get_query = function(doc,cdt,cdn) { WHERE `tabItem`.`docstatus`!= 2 AND ifnull(`tabItem`.`has_serial_no`, "No") = "Yes" \ AND (ifnull(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` > NOW() OR `tabItem`.`end_of_life`="0000-00-00") \ AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.`name` ASC LIMIT 50'; -} \ No newline at end of file +} + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js index b40a4137b8..859bd5823f 100644 --- a/stock/doctype/stock_entry/stock_entry.js +++ b/stock/doctype/stock_entry/stock_entry.js @@ -230,3 +230,5 @@ cur_frm.cscript.validate_items = function(doc) { validated = false; } } + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/support/doctype/communication/communication.js b/support/doctype/communication/communication.js index 76161ab2db..9995729b99 100644 --- a/support/doctype/communication/communication.js +++ b/support/doctype/communication/communication.js @@ -136,4 +136,6 @@ cur_frm.cscript.contact = function(doc, dt, dn) { cur_frm.cscript.hide_dialog = function() { if(cur_frm.communication_list) cur_frm.communication_list.run(); -} \ No newline at end of file +} + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/support/doctype/customer_issue/customer_issue.js b/support/doctype/customer_issue/customer_issue.js index 545ff5669f..81c10d4d11 100644 --- a/support/doctype/customer_issue/customer_issue.js +++ b/support/doctype/customer_issue/customer_issue.js @@ -144,3 +144,5 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 \ AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50'; } + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.js b/support/doctype/maintenance_schedule/maintenance_schedule.js index efa3eac037..21d2e62e53 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.js +++ b/support/doctype/maintenance_schedule/maintenance_schedule.js @@ -131,3 +131,5 @@ cur_frm.cscript.generate_schedule = function(doc, cdt, cdn) { 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'; } + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/support/doctype/maintenance_visit/maintenance_visit.js b/support/doctype/maintenance_visit/maintenance_visit.js index 1e5e9c8009..a53c0903c0 100644 --- a/support/doctype/maintenance_visit/maintenance_visit.js +++ b/support/doctype/maintenance_visit/maintenance_visit.js @@ -114,3 +114,5 @@ cur_frm.fields_dict['maintenance_schedule'].get_query = function(doc) { 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'; } + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/support/doctype/support_ticket/support_ticket.js b/support/doctype/support_ticket/support_ticket.js index 50f49b011c..6ab2c68972 100644 --- a/support/doctype/support_ticket/support_ticket.js +++ b/support/doctype/support_ticket/support_ticket.js @@ -189,4 +189,6 @@ EmailMessage = function(parent, args, list, idx) { this.make(); } -cur_frm.fields_dict.allocated_to.get_query = erpnext.utils.profile_query; \ No newline at end of file +cur_frm.fields_dict.allocated_to.get_query = erpnext.utils.profile_query; + +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/support/doctype/support_ticket/support_ticket.py b/support/doctype/support_ticket/support_ticket.py index d04f4730f1..dde4fd2c7b 100644 --- a/support/doctype/support_ticket/support_ticket.py +++ b/support/doctype/support_ticket/support_ticket.py @@ -56,7 +56,7 @@ class DocType(TransactionBase): msg=response) self.doc.new_response = None - webnotes.conn.set(self.doc,'status','Waiting for Customer') + webnotes.conn.set(self.doc, 'status', 'Waiting for Customer') self.make_response_record(response) def last_response(self): diff --git a/utilities/doctype/address/address.js b/utilities/doctype/address/address.js index 3b27ba81f0..0ace167887 100644 --- a/utilities/doctype/address/address.js +++ b/utilities/doctype/address/address.js @@ -41,4 +41,4 @@ cur_frm.cscript.hide_dialog = function() { cur_frm.address_list.run(); } - +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file diff --git a/utilities/doctype/contact/contact.js b/utilities/doctype/contact/contact.js index 1b0894ee21..5c71acf4a5 100644 --- a/utilities/doctype/contact/contact.js +++ b/utilities/doctype/contact/contact.js @@ -42,4 +42,4 @@ cur_frm.cscript.hide_dialog = function() { cur_frm.contact_list.run(); } - +cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;