From ab462d2000cfd11196214fb7977e2bd22f8fd4ec Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 9 Jul 2013 16:18:52 +0530 Subject: [PATCH] [get_query]to server side --- accounts/doctype/pos_setting/pos_setting.js | 4 +- .../purchase_invoice/purchase_invoice.js | 9 ++- .../doctype/sales_invoice/sales_invoice.js | 41 ----------- controllers/queries.py | 6 +- hr/doctype/appraisal/appraisal.js | 6 +- hr/doctype/attendance/attendance.js | 6 +- hr/doctype/employee/employee.js | 6 +- hr/doctype/expense_claim/expense_claim.js | 6 +- .../leave_allocation/leave_allocation.js | 6 +- hr/doctype/salary_slip/salary_slip.js | 6 +- .../salary_structure/salary_structure.js | 6 +- .../production_order/production_order.js | 16 +++-- .../production_planning_tool.js | 13 +++- projects/doctype/project/project.js | 6 +- projects/doctype/task/task.js | 6 +- projects/doctype/task/task.py | 9 +++ selling/doctype/customer/customer.js | 11 ++- .../installation_note/installation_note.js | 37 +++++++--- selling/doctype/lead/lead.js | 9 ++- selling/doctype/opportunity/opportunity.js | 54 +++++++++----- selling/doctype/opportunity/opportunity.py | 11 ++- selling/doctype/quotation/quotation.js | 56 +++++---------- selling/doctype/quotation/quotation.py | 31 +++++++- selling/doctype/sales_bom/sales_bom.js | 9 ++- selling/doctype/sales_bom/sales_bom.py | 10 +++ selling/doctype/sales_common/sales_common.js | 3 +- selling/doctype/sales_order/sales_order.js | 16 +++-- .../authorization_rule/authorization_rule.js | 44 +++++++++--- setup/doctype/company/company.js | 50 ++++++++----- .../contact_control/contact_control.js | 7 +- .../doctype/customer_group/customer_group.js | 14 ++-- setup/doctype/item_group/item_group.js | 8 ++- setup/doctype/sales_partner/sales_partner.js | 5 +- setup/doctype/sales_person/sales_person.js | 16 ++++- setup/doctype/territory/territory.js | 13 +++- stock/doctype/batch/batch.js | 9 ++- stock/doctype/delivery_note/delivery_note.js | 32 +++++---- stock/doctype/item/item.js | 53 ++++++++++---- .../landed_cost_wizard/landed_cost_wizard.js | 10 ++- stock/doctype/packing_slip/packing_slip.js | 14 ++-- stock/doctype/packing_slip/packing_slip.py | 11 ++- .../purchase_receipt/purchase_receipt.js | 32 ++++++--- stock/doctype/serial_no/serial_no.js | 26 +++++-- stock/doctype/stock_entry/stock_entry.js | 49 ++++++++----- stock/doctype/stock_entry/stock_entry.py | 32 +++++++-- .../stock_reconciliation.js | 4 +- .../stock_uom_replace_utility.js | 4 +- .../doctype/customer_issue/customer_issue.js | 70 ++++++++++++------- .../maintenance_schedule.js | 27 +++++-- .../maintenance_schedule.py | 14 +++- .../maintenance_visit/maintenance_visit.js | 60 +++++++++++----- .../doctype/support_ticket/support_ticket.js | 3 +- 52 files changed, 692 insertions(+), 314 deletions(-) diff --git a/accounts/doctype/pos_setting/pos_setting.js b/accounts/doctype/pos_setting/pos_setting.js index a51d93edce..59c4e01d0c 100755 --- a/accounts/doctype/pos_setting/pos_setting.js +++ b/accounts/doctype/pos_setting/pos_setting.js @@ -97,4 +97,6 @@ cur_frm.fields_dict["expense_account"].get_query = function(doc) { } } -cur_frm.fields_dict.user.get_query = erpnext.utils.profile_query; \ No newline at end of file +cur_frm.fields_dict.user.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.profile_query"} +} \ No newline at end of file diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.js b/accounts/doctype/purchase_invoice/purchase_invoice.js index 27ca6fcf62..60f0c4f5ca 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -166,9 +166,12 @@ cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { } cur_frm.fields_dict['entries'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) { - return erpnext.queries.item({ - 'ifnull(tabItem.is_purchase_item, "No")': 'Yes' - }) + return { + query:"controllers.queries.item_query", + filters:{ + 'is_purchase_item': 'Yes' + } + } } cur_frm.fields_dict['credit_to'].get_query = function(doc) { diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index 7203a1ce9e..947574fe02 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -366,47 +366,6 @@ cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = functio } } -// Sales Order -// ----------- -cur_frm.fields_dict.sales_order_main.get_query = function(doc) { - var filter = [ - ['Sales Order','company','=',doc.company], - ['Sales Order','docstatus','=',1], - ['Sales Order','status','!=','Stopped'], - ['Sales Order','per_billed','<',99.99] - ]; - var cond = []; - if (doc.customer) cond = ['Sales Order', 'customer', '=', doc.customer]; - // return 'SELECT DISTINCT `tabSales Order`.`name` FROM `tabSales Order` WHERE `tabSales Order`.company = "' + doc.company + '" and `tabSales Order`.`docstatus` = 1 and `tabSales Order`.`status` != "Stopped" and ifnull(`tabSales Order`.per_billed,0) < 99.99 and `tabSales Order`.`customer` = "' + doc.customer + '" and `tabSales Order`.%(key)s LIKE "%s" ORDER BY `tabSales Order`.`name` DESC LIMIT 50'; - filter.push(cond); - return{ - filters: filter - } -} - -// Delivery Note -// -------------- -cur_frm.fields_dict.delivery_note_main.get_query = function(doc) { - var filter = [ - ['Delivery Note', 'company', '=', doc.company], - ['Delivery Note', 'docstatus', '=', 1], - ['Delivery Note', 'per_billed', '<', 99.99] - ]; - var cond = []; - if (doc.customer) ['Delivery Note', 'customer', '=', doc.customer]; - // return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` \ - // WHERE `tabDelivery Note`.company = "' + doc.company - // + '" and `tabDelivery Note`.`docstatus` = 1 and \ - // ifnull(`tabDelivery Note`.per_billed,0) < 99.99 and \ - // `tabDelivery Note`.`customer` = "' - // + doc.customer + '" and `tabDelivery Note`.%(key)s LIKE "%s" \ - // ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50'; - filter.push(cond); - return{ - filters: filter - } -} - cur_frm.cscript.income_account = function(doc, cdt, cdn){ cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "income_account"); } diff --git a/controllers/queries.py b/controllers/queries.py index 896147fb2b..ac8ab25122 100644 --- a/controllers/queries.py +++ b/controllers/queries.py @@ -173,8 +173,8 @@ def bom(doctype, txt, searchfield, start, page_len, filters): def get_project_name(doctype, txt, searchfield, start, page_len, filters): cond = '' if filters['customer']: - cond = '(`tabProject`.customer = filter[customer] or ifnull(`tabProject`.customer,"")="") ' + cond = '(`tabProject`.customer = "' + filters['customer'] + '" or ifnull(`tabProject`.customer,"")="") and' return webnotes.conn.sql("""select `tabProject`.name from `tabProject` - where `tabProject`.status not in ("Completed", "Cancelled") and %(cond)s %(mcond)s - `tabProject`.name like "%(txt)s" order by `tabProject`.name asc limit %(start)s, %(page_len)s """ % + where `tabProject`.status not in ("Completed", "Cancelled") and %(cond)s + `tabProject`.name like "%(txt)s" %(mcond)s order by `tabProject`.name asc limit %(start)s, %(page_len)s """ % {'cond': cond,'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),'start': start, 'page_len': page_len}) \ No newline at end of file diff --git a/hr/doctype/appraisal/appraisal.js b/hr/doctype/appraisal/appraisal.js index 601f3fc3cb..ac2b1234d2 100644 --- a/hr/doctype/appraisal/appraisal.js +++ b/hr/doctype/appraisal/appraisal.js @@ -83,4 +83,8 @@ cur_frm.cscript.calculate_total = function(doc,cdt,cdn){ refresh_field('total_score'); } -cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query; \ No newline at end of file +cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.employee_query" + } +} \ No newline at end of file diff --git a/hr/doctype/attendance/attendance.js b/hr/doctype/attendance/attendance.js index 3ba986891b..94b32a36c0 100644 --- a/hr/doctype/attendance/attendance.js +++ b/hr/doctype/attendance/attendance.js @@ -22,4 +22,8 @@ cur_frm.cscript.employee = function(doc,cdt,cdn){ refresh_field('employee_name'); } -cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query; \ No newline at end of file +cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.employee_query" + } +} \ No newline at end of file diff --git a/hr/doctype/employee/employee.js b/hr/doctype/employee/employee.js index 5a2dbab87f..3c19548bc5 100644 --- a/hr/doctype/employee/employee.js +++ b/hr/doctype/employee/employee.js @@ -18,8 +18,10 @@ wn.provide("erpnext.hr"); erpnext.hr.EmployeeController = wn.ui.form.Controller.extend({ setup: function() { this.setup_leave_approver_select(); - this.frm.fields_dict.user_id.get_query = erpnext.utils.profile_query; - this.frm.fields_dict.reports_to.get_query = erpnext.utils.employee_query; + this.frm.fields_dict.user_id.get_query = function(doc,cdt,cdn) { + return { query:"controllers.queries.profile_query"} } + this.frm.fields_dict.reports_to.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.employee_query"} } }, onload: function() { diff --git a/hr/doctype/expense_claim/expense_claim.js b/hr/doctype/expense_claim/expense_claim.js index 5b136d0a2e..406b57a1e7 100644 --- a/hr/doctype/expense_claim/expense_claim.js +++ b/hr/doctype/expense_claim/expense_claim.js @@ -35,7 +35,11 @@ cur_frm.cscript.onload = function(doc,cdt,cdn){ } }); - cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query; + cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.employee_query" + } + } } cur_frm.cscript.clear_sanctioned = function(doc) { diff --git a/hr/doctype/leave_allocation/leave_allocation.js b/hr/doctype/leave_allocation/leave_allocation.js index a26d211bbd..80445c159c 100755 --- a/hr/doctype/leave_allocation/leave_allocation.js +++ b/hr/doctype/leave_allocation/leave_allocation.js @@ -79,4 +79,8 @@ calculate_total_leaves_allocated = function(doc, dt, dn) { } } -cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query; \ No newline at end of file +cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.employee_query" + } +} \ No newline at end of file diff --git a/hr/doctype/salary_slip/salary_slip.js b/hr/doctype/salary_slip/salary_slip.js index fc58271336..9885763ff2 100644 --- a/hr/doctype/salary_slip/salary_slip.js +++ b/hr/doctype/salary_slip/salary_slip.js @@ -139,4 +139,8 @@ cur_frm.cscript.validate = function(doc, dt, dn) { calculate_all(doc, dt, dn); } -cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query; \ No newline at end of file +cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.employee_query" + } +} \ No newline at end of file diff --git a/hr/doctype/salary_structure/salary_structure.js b/hr/doctype/salary_structure/salary_structure.js index 2979243173..065bb47711 100644 --- a/hr/doctype/salary_structure/salary_structure.js +++ b/hr/doctype/salary_structure/salary_structure.js @@ -72,4 +72,8 @@ cur_frm.cscript.validate = function(doc, cdt, cdn) { calculate_totals(doc, cdt, cdn); } -cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query; \ No newline at end of file +cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.employee_query" + } +} \ No newline at end of file diff --git a/manufacturing/doctype/production_order/production_order.js b/manufacturing/doctype/production_order/production_order.js index 77dce03d58..e3518591b3 100644 --- a/manufacturing/doctype/production_order/production_order.js +++ b/manufacturing/doctype/production_order/production_order.js @@ -101,13 +101,21 @@ cur_frm.cscript.make_se = function(doc, purpose) { } cur_frm.fields_dict['production_item'].get_query = function(doc) { - return 'SELECT DISTINCT `tabItem`.`name`, `tabItem`.`description` FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.docstatus != 2 AND `tabItem`.is_pro_applicable = "Yes" AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.`name` LIMIT 50'; + return { + filters:[ + ['Item', 'is_pro_applicable', '=', 'Yes'] + ] + } + // return 'SELECT DISTINCT `tabItem`.`name`, `tabItem`.`description` FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.docstatus != 2 AND `tabItem`.is_pro_applicable = "Yes" AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.`name` LIMIT 50'; } cur_frm.fields_dict['project_name'].get_query = function(doc, dt, dn) { - return 'SELECT `tabProject`.name FROM `tabProject` \ - WHERE `tabProject`.status not in ("Completed", "Cancelled") \ - AND `tabProject`.name LIKE "%s" ORDER BY `tabProject`.name ASC LIMIT 50'; + return{ + filters:['Project', 'status', 'not in', 'Completed, Cancelled'] + } + // return 'SELECT `tabProject`.name FROM `tabProject` \ + // WHERE `tabProject`.status not in ("Completed", "Cancelled") \ + // AND `tabProject`.name LIKE "%s" ORDER BY `tabProject`.name ASC LIMIT 50'; } diff --git a/manufacturing/doctype/production_planning_tool/production_planning_tool.js b/manufacturing/doctype/production_planning_tool/production_planning_tool.js index 95b84b2078..9158748392 100644 --- a/manufacturing/doctype/production_planning_tool/production_planning_tool.js +++ b/manufacturing/doctype/production_planning_tool/production_planning_tool.js @@ -53,11 +53,18 @@ cur_frm.fields_dict['pp_details'].grid.get_field('item_code').get_query = functi cur_frm.fields_dict['pp_details'].grid.get_field('bom_no').get_query = function(doc) { var d = locals[this.doctype][this.docname]; if (d.item_code) { - return erpnext.queries.bom({item: cstr(d.item_code)}); + return { + query:"controllers.queries.bom", + filters:{'item': cstr(d.item_code)} + } } else msgprint(" Please enter Item first"); } -cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.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 + cur_frm.fields_dict.customer.get_query; \ No newline at end of file diff --git a/projects/doctype/project/project.js b/projects/doctype/project/project.js index a6f32cb2db..9d04477a29 100644 --- a/projects/doctype/project/project.js +++ b/projects/doctype/project/project.js @@ -28,4 +28,8 @@ cur_frm.cscript.refresh = function(doc) { } } -cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.customer_query" + } +} \ No newline at end of file diff --git a/projects/doctype/task/task.js b/projects/doctype/task/task.js index 131b5fdfb5..097119ffb6 100644 --- a/projects/doctype/task/task.js +++ b/projects/doctype/task/task.js @@ -21,9 +21,9 @@ cur_frm.add_fetch("project", "company", "company"); erpnext.projects.Task = wn.ui.form.Controller.extend({ setup: function() { this.frm.fields_dict.project.get_query = function() { - return "select name from `tabProject` \ - where %(key)s like \"%s\" \ - order by name asc limit 50"; + return { + query: "projects.doctype.tast.task.get_project" + } }; }, diff --git a/projects/doctype/task/task.py b/projects/doctype/task/task.py index 1df8547690..1dfcdc1af1 100644 --- a/projects/doctype/task/task.py +++ b/projects/doctype/task/task.py @@ -92,3 +92,12 @@ def get_events(start, end, filters=None): }, as_dict=True, update={"allDay": 0}) return data + +def get_project(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + return webnotes.conn.sql(""" select name from `tabProject` + where %(key)s like %(txt)s %(mcond)s + order by name limit %(start)s, %(page_len)s + """ % {'key': searchfield, 'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield), + 'start': start, 'page_len': page_len}) \ No newline at end of file diff --git a/selling/doctype/customer/customer.js b/selling/doctype/customer/customer.js index 914836c934..f92a2a90e6 100644 --- a/selling/doctype/customer/customer.js +++ b/selling/doctype/customer/customer.js @@ -122,8 +122,15 @@ cur_frm.cscript.make_contact = function() { } cur_frm.fields_dict['customer_group'].get_query = function(doc,dt,dn) { - return 'SELECT `tabCustomer Group`.`name`, `tabCustomer Group`.`parent_customer_group` FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "No" AND `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" ORDER BY `tabCustomer Group`.`name` ASC LIMIT 50'; + return{ + filters:{'is_group': 'No'} + } + // return 'SELECT `tabCustomer Group`.`name`, `tabCustomer Group`.`parent_customer_group` FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "No" AND `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" ORDER BY `tabCustomer Group`.`name` ASC LIMIT 50'; } -cur_frm.fields_dict.lead_name.get_query = erpnext.utils.lead_query; \ No newline at end of file +cur_frm.fields_dict.lead_name.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.lead_query" + } +} \ 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 4fd8678eaf..8574da3123 100644 --- a/selling/doctype/installation_note/installation_note.js +++ b/selling/doctype/installation_note/installation_note.js @@ -62,16 +62,27 @@ cur_frm.cscript.onload = function(doc, dt, dn) { cur_frm.fields_dict['delivery_note_no'].get_query = function(doc) { doc = locals[this.doctype][this.docname]; - var cond = ''; - if(doc.customer) { - cond = '`tabDelivery Note`.customer = "'+doc.customer+'" AND'; + var filter = { + 'company': doc.company, + 'docstatus': 1, + 'per_installed': 99.99 + }; + if(doc.customer) filter['customer'] = doc.customer; + return{ + filters:filter } - return repl('SELECT DISTINCT `tabDelivery Note`.name, `tabDelivery Note`.customer_name FROM `tabDelivery Note`, `tabDelivery Note Item` WHERE `tabDelivery Note`.company = "%(company)s" AND `tabDelivery Note`.docstatus = 1 AND ifnull(`tabDelivery Note`.per_installed,0) < 99.99 AND %(cond)s `tabDelivery Note`.name LIKE "%s" ORDER BY `tabDelivery Note`.name DESC LIMIT 50', {company:doc.company, cond:cond}); + // { + // cond = '`tabDelivery Note`.customer = "'+doc.customer+'" AND'; + // } + // return repl('SELECT DISTINCT `tabDelivery Note`.name, `tabDelivery Note`.customer_name FROM `tabDelivery Note`, `tabDelivery Note Item` WHERE `tabDelivery Note`.company = "%(company)s" AND `tabDelivery Note`.docstatus = 1 AND ifnull(`tabDelivery Note`.per_installed,0) < 99.99 AND %(cond)s `tabDelivery Note`.name LIKE "%s" ORDER BY `tabDelivery Note`.name DESC LIMIT 50', {company:doc.company, cond:cond}); } 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{ + filters{ 'is_group': "No" } + } + // 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.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { @@ -79,11 +90,21 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc } cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; + return{ + filters: { 'customer': doc.customer } + } + // return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; } 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'; + return{ + filters: { 'customer': doc.customer } + } + // 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 +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.customer_query" + } +} \ No newline at end of file diff --git a/selling/doctype/lead/lead.js b/selling/doctype/lead/lead.js index 40cf454f01..a20b3314a4 100644 --- a/selling/doctype/lead/lead.js +++ b/selling/doctype/lead/lead.js @@ -20,16 +20,19 @@ wn.require('app/setup/doctype/contact_control/contact_control.js'); wn.provide("erpnext"); erpnext.LeadController = wn.ui.form.Controller.extend({ setup: function() { - this.frm.fields_dict.customer.get_query = erpnext.utils.customer_query; + this.frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return { query:"controllers.queries.customer_query" } } }, onload: function() { if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) { - cur_frm.fields_dict.lead_owner.get_query = erpnext.utils.profile_query; + cur_frm.fields_dict.lead_owner.get_query = function(doc,cdt,cdn) { + return { query:"controllers.queries.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.fields_dict.contact_by.get_query = function(doc,cdt,cdn) { + return { query:"controllers.queries.profile_query" } } } if(in_list(user_roles,'System Manager')) { diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index bc10c9b0bb..f88402d882 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -109,7 +109,8 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { } 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.fields_dict.contact_by.get_query = function(doc,cdt,cdn) { + return { query:"controllers.queries.profile_query" } } } if(doc.customer && !doc.customer_name) cur_frm.cscript.customer(doc); @@ -153,23 +154,30 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc } cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name, address_line1, city FROM tabAddress \ - WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND \ - %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; + return { + filters:{'customer':doc.customer} + } + // return 'SELECT name, address_line1, city FROM tabAddress \ + // WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND \ + // %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; } cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { if (!doc.customer) msgprint("Please select customer first"); else { - return 'SELECT name, CONCAT(first_name," ",ifnull(last_name,"")) As FullName, \ - department, designation FROM tabContact WHERE customer = "'+ doc.customer + - '" AND docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; + filters:{'customer':doc.customer} + // return 'SELECT name, CONCAT(first_name," ",ifnull(last_name,"")) As FullName, \ + // department, designation FROM tabContact WHERE customer = "'+ doc.customer + + // '" AND docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; } } // lead cur_frm.fields_dict['lead'].get_query = function(doc,cdt,cdn){ - return 'SELECT `tabLead`.name, `tabLead`.lead_name FROM `tabLead` WHERE `tabLead`.%(key)s LIKE "%s" ORDER BY `tabLead`.`name` ASC LIMIT 50'; + return { + query: "selling.doctype.opportunity.opportunity.get_lead" + } + // return 'SELECT `tabLead`.name, `tabLead`.lead_name FROM `tabLead` WHERE `tabLead`.%(key)s LIKE "%s" ORDER BY `tabLead`.`name` ASC LIMIT 50'; } cur_frm.cscript.lead = function(doc, cdt, cdn) { @@ -185,14 +193,17 @@ cur_frm.cscript.lead = function(doc, cdt, cdn) { } cur_frm.fields_dict['enquiry_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) { - if (doc.enquiry_type == 'Maintenance') - return erpnext.queries.item({ - 'ifnull(tabItem.is_service_item, "No")': 'Yes' - }); - else - return erpnext.queries.item({ - 'ifnull(tabItem.is_sales_item, "No")': 'Yes' - }); + if (doc.enquiry_type == 'Maintenance') { + return { + query:"controllers.queries.item_query", + filters:{ 'is_service_item': 'Yes' } + } + } else { + return { + query:"controllers.queries.item_query", + filters:{ 'is_sales_item': 'Yes' } + } + } } cur_frm.cscript['Declare Opportunity Lost'] = function(){ @@ -229,8 +240,13 @@ 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{ + filters:{'is_group': 'No'} + } + // 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; +cur_frm.fields_dict.lead.get_query = function(doc,cdt,cdn) { + return { query:"controllers.queries.lead_query" } } -cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return { query:"controllers.queries.customer_query" } } \ No newline at end of file diff --git a/selling/doctype/opportunity/opportunity.py b/selling/doctype/opportunity/opportunity.py index cced9abfa8..6217821499 100644 --- a/selling/doctype/opportunity/opportunity.py +++ b/selling/doctype/opportunity/opportunity.py @@ -202,4 +202,13 @@ def make_quotation(source_name, target_doclist=None): } }, target_doclist) - return [d.fields for d in doclist] \ No newline at end of file + return [d.fields for d in doclist] + +def get_lead(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + return webnotes.conn.sql ("""select `tabLead`.name, `tabLead`.lead_name FROM `tabLead` + where `tabLead`.%(key)s like "%(txt)s" %(mcond)s + order by `tabLead`.`name` asc limit %(start)s, %(page_len)s + """ % {'key': searchfield, 'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield), + 'start': start, 'page_len': page_len}) \ No newline at end of file diff --git a/selling/doctype/quotation/quotation.js b/selling/doctype/quotation/quotation.js index 877f65c252..ccb4998eaf 100644 --- a/selling/doctype/quotation/quotation.js +++ b/selling/doctype/quotation/quotation.js @@ -118,7 +118,8 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc }),'', doc, dt, dn, 1); } -cur_frm.fields_dict.lead.get_query = erpnext.utils.lead_query; +cur_frm.fields_dict.lead.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.lead_query" } } cur_frm.cscript.lead = function(doc, cdt, cdn) { if(doc.lead) { @@ -186,45 +187,22 @@ cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query= if(doc.customer) { var export_rate_field = wn.meta.get_docfield(cdt, 'export_rate', cdn); var precision = (export_rate_field && export_rate_field.fieldtype) === 'Float' ? 6 : 2; - return repl("\ - select \ - item.name, \ - ( \ - select concat('Last Quote @ ', q.currency, ' ', \ - format(q_item.export_rate, %(precision)s)) \ - from `tabQuotation` q, `tabQuotation Item` q_item \ - where \ - q.name = q_item.parent \ - and q_item.item_code = item.name \ - and q.docstatus = 1 \ - and q.customer = \"%(cust)s\" \ - order by q.transaction_date desc \ - limit 1 \ - ) as quote_rate, \ - ( \ - select concat('Last Sale @ ', si.currency, ' ', \ - format(si_item.basic_rate, %(precision)s)) \ - from `tabSales Invoice` si, `tabSales Invoice Item` si_item \ - where \ - si.name = si_item.parent \ - and si_item.item_code = item.name \ - and si.docstatus = 1 \ - and si.customer = \"%(cust)s\" \ - order by si.posting_date desc \ - limit 1 \ - ) as sales_rate, \ - item.item_name, item.description \ - from `tabItem` item \ - where \ - item.%(key)s like \"%s\" \ - %(cond)s \ - limit 25", { - cust: doc.customer, - cond: cond, - precision: precision - }); + return { + query: "selling.doctype.quotation.quotation.quotation_details", + filters:{ + cust: doc.customer, + cond: cond, + precision: precision + } + } } else { - return repl("SELECT name, item_name, description FROM `tabItem` item WHERE item.%(key)s LIKE '%s' %(cond)s ORDER BY item.item_code DESC LIMIT 50", {cond:cond}); + return { + query: 'selling.doctype.quotation.quotation.quotation_details', + filters:{ + cond: cond, + } + } + // return repl("SELECT name, item_name, description FROM `tabItem` item WHERE item.%(key)s LIKE '%s' %(cond)s ORDER BY item.item_code DESC LIMIT 50", {cond:cond}); } } diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index 3f0974ed0c..152e909a2b 100644 --- a/selling/doctype/quotation/quotation.py +++ b/selling/doctype/quotation/quotation.py @@ -259,4 +259,33 @@ def make_sales_order(source_name, target_doclist=None): # postprocess: fetch shipping address, set missing values - return [d.fields for d in doclist] \ No newline at end of file + return [d.fields for d in doclist] + +def quotation_details(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + + if filters.has_key('cust') and filters.has_key('precision'): + return webnotes.conn.sql("""select item.name, + (select concat('Last Quote @ ', q.currency, ' ', format(q_item.export_rate, %(precision)s)) + from `tabQuotation` q, `tabQuotation Item` q_item + where q.name = q_item.parent and q_item.item_code = item.name + and q.docstatus = 1 and q.customer = "%(cust)s" + order by q.transaction_date desc + limit 1) as quote_rate, + (select concat('Last Sale @ ', si.currency, ' ', format(si_item.basic_rate, %(precision)s)) + from `tabSales Invoice` si, `tabSales Invoice Item` si_item + where si.name = si_item.parent and si_item.item_code = item.name + and si.docstatus = 1 and si.customer ="%(cust)s" + order by si.posting_date desc + limit 1) as sales_rate, + item.item_name, item.description + from `tabItem` item + where %(cond)s %(mcond)s and item.%(searchfield)s like '%(txt)s' order by item.name desc limit %(start)s, + %(page_len)s """ % {'precision': filters["precision"], 'cust': filters['cust'], + 'cond': filters['cond'], 'searchfield': searchfield, 'txt': "%%%s%%" % txt, + 'mcond': get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) + + else: + webnotes.conn.sql(""" select name, item_name, description from `tabItem` item + where %s %s and %s like %s order by name desc limit %s, %s""" % + ("%s", get_match_cond(doctype, searchfield), searchfield, "%s", "%s", "%s"), (filters["cond"], "%%%s%%" % txt, start, page_len)) \ No newline at end of file diff --git a/selling/doctype/sales_bom/sales_bom.js b/selling/doctype/sales_bom/sales_bom.js index b6ba77953f..f60b6e3122 100644 --- a/selling/doctype/sales_bom/sales_bom.js +++ b/selling/doctype/sales_bom/sales_bom.js @@ -24,9 +24,12 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { } cur_frm.fields_dict.new_item_code.get_query = function() { - return 'select name, description from tabItem where is_stock_item="No" and is_sales_item="Yes"\ - and name not in (select name from `tabSales BOM`)\ - and `%(key)s` like "%s"' + return{ + query: "selling.doctype.sales_bom.sales_bom.get_new_item_code" + } + // return 'select name, description from tabItem where is_stock_item="No" and is_sales_item="Yes"\ + // and name not in (select name from `tabSales BOM`)\ + // and `%(key)s` like "%s"' } cur_frm.fields_dict.new_item_code.query_description = 'Select Item where "Is Stock Item" is "No" \ and "Is Sales Item" is "Yes" and there is no other Sales BOM'; diff --git a/selling/doctype/sales_bom/sales_bom.py b/selling/doctype/sales_bom/sales_bom.py index 03479ebb95..13f68aa78c 100644 --- a/selling/doctype/sales_bom/sales_bom.py +++ b/selling/doctype/sales_bom/sales_bom.py @@ -83,3 +83,13 @@ class DocType: if l not in l2: return 0 return 1 + +def get_new_item_code(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + + return webnotes.conn.sql("""select name, description from tabItem + where is_stock_item="No" and is_sales_item="Yes" + and name not in (select name from `tabSales BOM`) and %s like "%s" + %s limit %s, %s""" % (searchfield, "%s", + get_match_cond(doctype, searchfield),"%s", "%s"), + ("%%%s%%" % txt, start, page_len)) \ 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 cf757a6cea..02db55a29d 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -59,7 +59,8 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ }); } - this.frm.fields_dict.customer.get_query = erpnext.utils.customer_query; + this.frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.customer_query" } } this.frm.fields_dict.lead && this.frm.set_query("lead", erpnext.utils.lead_query); diff --git a/selling/doctype/sales_order/sales_order.js b/selling/doctype/sales_order/sales_order.js index 27db426eb7..509ecf709f 100644 --- a/selling/doctype/sales_order/sales_order.js +++ b/selling/doctype/sales_order/sales_order.js @@ -154,12 +154,12 @@ cur_frm.cscript.new_contact = function(){ } cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) { - var cond = ''; - if(doc.customer) cond = '(`tabProject`.customer = "'+doc.customer+'" OR IFNULL(`tabProject`.customer,"")="") AND'; - return repl('SELECT `tabProject`.name FROM `tabProject` \ - WHERE `tabProject`.status not in ("Completed", "Cancelled") \ - AND %(cond)s `tabProject`.name LIKE "%s" \ - ORDER BY `tabProject`.name ASC LIMIT 50', {cond:cond}); + return { + query: "controllers.queries.get_project_name", + filters: { + 'customer': doc.customer + } + } } cur_frm.cscript['Stop Sales Order'] = function() { @@ -193,7 +193,9 @@ cur_frm.cscript['Unstop Sales Order'] = 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'; + return{ + filters:{ 'is_group': "No"} + } } cur_frm.cscript.on_submit = function(doc, cdt, cdn) { diff --git a/setup/doctype/authorization_rule/authorization_rule.js b/setup/doctype/authorization_rule/authorization_rule.js index 184c761b9d..76a87080c3 100644 --- a/setup/doctype/authorization_rule/authorization_rule.js +++ b/setup/doctype/authorization_rule/authorization_rule.js @@ -81,32 +81,56 @@ cur_frm.cscript.transaction = function(doc,cdt,cdn){ } -cur_frm.fields_dict.system_user.get_query = erpnext.utils.profile_query; +cur_frm.fields_dict.system_user.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.profile_query" } } -cur_frm.fields_dict.approving_user.get_query = erpnext.utils.profile_query; +cur_frm.fields_dict.approving_user.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.profile_query" } } + +cur_frm.fields_dict['approving_role'].get_query = cur_frm.fields_dict['system_role'].get_query; // System Role Trigger // ----------------------- 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' + return{ + filters:[ + ['Role', 'name', 'not in', 'Administrator, Guest, All'] + ] + } + + // return 'SELECT tabRole.name FROM tabRole WHERE tabRole.name not in ("Administrator","Guest","All") AND tabRole.%(key)s LIKE "%s" LIMIT 50' } // Approving Role Trigger // ----------------------- -cur_frm.fields_dict['approving_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' -} +// cur_frm.fields_dict['approving_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' +// } // Master Name Trigger // -------------------- cur_frm.fields_dict['master_name'].get_query = function(doc){ if(doc.based_on == 'Customerwise Discount') - return 'SELECT `tabCustomer`.`name` FROM `tabCustomer` WHERE `tabCustomer`.docstatus !=2 and `tabCustomer`.`name` LIKE "%s" ORDER BY `tabCustomer`.`name` DESC LIMIT 50'; + return { + filters:[ + ['Customer', 'docstatus', '!=', 2] + ] + } + // return 'SELECT `tabCustomer`.`name` FROM `tabCustomer` WHERE `tabCustomer`.docstatus !=2 and `tabCustomer`.`name` LIKE "%s" ORDER BY `tabCustomer`.`name` DESC LIMIT 50'; else if(doc.based_on == 'Itemwise Discount') - return 'SELECT `tabItem`.`name` FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) and `tabItem`.is_sales_item = "Yes" and tabItem.%(key)s LIKE "%s" ORDER BY `tabItem`.`name` DESC LIMIT 50'; + return { + query: "controllers.queries.item_query" + } + // return 'SELECT `tabItem`.`name` FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) and `tabItem`.is_sales_item = "Yes" and tabItem.%(key)s LIKE "%s" ORDER BY `tabItem`.`name` DESC LIMIT 50'; else - return 'SELECT `tabItem`.`name` FROM `tabItem` WHERE `tabItem`.`name` = "cheating done to avoid null" ORDER BY `tabItem`.`name` DESC LIMIT 50'; + return { + filters: [ + ['Item', 'name', '=', 'cheating done to avoid null'] + ] + } + // return 'SELECT `tabItem`.`name` FROM `tabItem` WHERE `tabItem`.`name` = "cheating done to avoid null" ORDER BY `tabItem`.`name` DESC LIMIT 50'; } -cur_frm.fields_dict.to_emp.get_query = erpnext.utils.employee_query; \ No newline at end of file +cur_frm.fields_dict.to_emp.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.employee_query" } } \ No newline at end of file diff --git a/setup/doctype/company/company.js b/setup/doctype/company/company.js index 489ed0ce68..60a32ae10a 100644 --- a/setup/doctype/company/company.js +++ b/setup/doctype/company/company.js @@ -45,43 +45,60 @@ cur_frm.cscript.abbr = function(doc){ } } +cur_frm.fields_dict.default_cash_account.get_query = cur_frm.fields_dict.default_bank_account.get_query; + cur_frm.fields_dict.default_bank_account.get_query = function(doc) { - return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; + return{ + filters:{ + 'company': doc.name, + 'group_or_ledger': "Ledger", + 'account_type': "Bank or Cash" + } + } + // return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; } -cur_frm.fields_dict.default_cash_account.get_query = function(doc) { - return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; -} +// cur_frm.fields_dict.default_cash_account.get_query = function(doc) { +// return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; +// } +cur_frm.fields_dict.payables_group.get_query = cur_frm.fields_dict.receivables_group.get_query; cur_frm.fields_dict.receivables_group.get_query = function(doc) { - return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Group" AND `tabAccount`.docstatus != 2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; + return{ + filters:{ + 'company': doc.name, + 'group_or_ledger': "Group" + } + } + // return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Group" AND `tabAccount`.docstatus != 2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; } - -cur_frm.fields_dict.payables_group.get_query = function(doc) { - return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Group" AND `tabAccount`.docstatus != 2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; -} +// cur_frm.fields_dict.payables_group.get_query = function(doc) { +// return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Group" AND `tabAccount`.docstatus != 2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50'; +// } if (sys_defaults.auto_inventory_accounting) { cur_frm.fields_dict["stock_in_hand_account"].get_query = function(doc) { return { - "query": "accounts.utils.get_account_list", + // "query": "accounts.utils.get_account_list", "filters": { "is_pl_account": "No", "debit_or_credit": "Debit", - "company": doc.name + "company": doc.name, + 'group_or_ledger': "Ledger" } } } cur_frm.fields_dict["stock_adjustment_account"].get_query = function(doc) { return { - "query": "accounts.utils.get_account_list", + // "query": "accounts.utils.get_account_list", "filters": { "is_pl_account": "Yes", "debit_or_credit": "Debit", - "company": doc.name + "company": doc.name, + 'group_or_ledger': "Ledger" } } } @@ -91,18 +108,19 @@ if (sys_defaults.auto_inventory_accounting) { cur_frm.fields_dict["stock_received_but_not_billed"].get_query = function(doc) { return { - "query": "accounts.utils.get_account_list", + // "query": "accounts.utils.get_account_list", "filters": { "is_pl_account": "No", "debit_or_credit": "Credit", - "company": doc.name + "company": doc.name, + 'group_or_ledger': "Ledger" } } } cur_frm.fields_dict["stock_adjustment_cost_center"].get_query = function(doc) { return { - "query": "accounts.utils.get_cost_center_list", + // "query": "accounts.utils.get_cost_center_list", "filters": {"company": doc.name} } } diff --git a/setup/doctype/contact_control/contact_control.js b/setup/doctype/contact_control/contact_control.js index c427ec09fd..9d4d8bf94c 100755 --- a/setup/doctype/contact_control/contact_control.js +++ b/setup/doctype/contact_control/contact_control.js @@ -24,7 +24,12 @@ cur_frm.cscript.country = function(doc, dt, dn) { // --------------------------- if(cur_frm.fields_dict['territory']){ cur_frm.fields_dict['territory'].get_query = function(doc,dt,dn) { - 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 { + filters: { + 'is_group' = "No" + } + } + // 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'; } } diff --git a/setup/doctype/customer_group/customer_group.js b/setup/doctype/customer_group/customer_group.js index af0c6f0b44..18931eb071 100644 --- a/setup/doctype/customer_group/customer_group.js +++ b/setup/doctype/customer_group/customer_group.js @@ -30,8 +30,14 @@ cur_frm.cscript.set_root_readonly = function(doc) { //get query select Customer Group cur_frm.fields_dict['parent_customer_group'].get_query = function(doc,cdt,cdn) { - return 'SELECT `tabCustomer Group`.`name`,`tabCustomer Group`.`parent_customer_group` \ - FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "Yes" AND \ - `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" \ - ORDER BY `tabCustomer Group`.`name` ASC LIMIT 50'; + return{ + searchfield:['name', 'parent_customer_group'], + filters: { + 'is_group': "Yes" + } + } + // return 'SELECT `tabCustomer Group`.`name`,`tabCustomer Group`.`parent_customer_group` \ + // FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "Yes" AND \ + // `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" \ + // ORDER BY `tabCustomer Group`.`name` ASC LIMIT 50'; } \ No newline at end of file diff --git a/setup/doctype/item_group/item_group.js b/setup/doctype/item_group/item_group.js index 6bb6fe309d..581039370b 100644 --- a/setup/doctype/item_group/item_group.js +++ b/setup/doctype/item_group/item_group.js @@ -34,5 +34,11 @@ cur_frm.cscript.set_root_readonly = function(doc) { //get query select item group cur_frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) { - return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` FROM `tabItem Group` WHERE `tabItem Group`.`is_group` = "Yes" AND `tabItem Group`.`docstatus`!= 2 AND `tabItem Group`.`name` !="'+doc.item_group_name+'" AND `tabItem Group`.%(key)s LIKE "%s" ORDER BY `tabItem Group`.`name` ASC LIMIT 50'; + return{ + filters:[ + ['Item Group', 'is_group', '=', 'Yes'], + ['Item Group', 'naem', '!=', doc.item_group_name] + ] + } + // return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` FROM `tabItem Group` WHERE `tabItem Group`.`is_group` = "Yes" AND `tabItem Group`.`docstatus`!= 2 AND `tabItem Group`.`name` !="'+doc.item_group_name+'" AND `tabItem Group`.%(key)s LIKE "%s" ORDER BY `tabItem Group`.`name` ASC LIMIT 50'; } \ No newline at end of file diff --git a/setup/doctype/sales_partner/sales_partner.js b/setup/doctype/sales_partner/sales_partner.js index c5f0dba7dd..5db60c5951 100644 --- a/setup/doctype/sales_partner/sales_partner.js +++ b/setup/doctype/sales_partner/sales_partner.js @@ -97,5 +97,8 @@ cur_frm.cscript.make_contact = function() { } cur_frm.fields_dict['partner_target_details'].grid.get_field("item_group").get_query = function(doc, dt, dn) { - return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` FROM `tabItem Group` WHERE `tabItem Group`.is_group="No" AND `tabItem Group`.docstatus != 2 AND `tabItem Group`.%(key)s LIKE "%s" LIMIT 50' + return{ + filters:{ 'is_group': "No" } + } + // return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` FROM `tabItem Group` WHERE `tabItem Group`.is_group="No" AND `tabItem Group`.docstatus != 2 AND `tabItem Group`.%(key)s LIKE "%s" LIMIT 50' } \ No newline at end of file diff --git a/setup/doctype/sales_person/sales_person.js b/setup/doctype/sales_person/sales_person.js index c52948803f..e0d06395e0 100644 --- a/setup/doctype/sales_person/sales_person.js +++ b/setup/doctype/sales_person/sales_person.js @@ -35,11 +35,21 @@ cur_frm.cscript.onload = function(){ //get query select sales person cur_frm.fields_dict['parent_sales_person'].get_query = function(doc,cdt,cdn) { - return 'SELECT `tabSales Person`.`name`,`tabSales Person`.`parent_sales_person` FROM `tabSales Person` WHERE `tabSales Person`.`is_group` = "Yes" AND `tabSales Person`.`docstatus`!= 2 AND `tabSales Person`.`name` !="'+doc.sales_person_name+'" AND `tabSales Person`.%(key)s LIKE "%s" ORDER BY `tabSales Person`.`name` ASC LIMIT 50'; + return{ + filters:[ + ['Sales Person', 'is_group', '=', 'Yes'], + ['Sales Person', 'name', '!=', doc.sales_person_name] + ] + } + // return 'SELECT `tabSales Person`.`name`,`tabSales Person`.`parent_sales_person` FROM `tabSales Person` WHERE `tabSales Person`.`is_group` = "Yes" AND `tabSales Person`.`docstatus`!= 2 AND `tabSales Person`.`name` !="'+doc.sales_person_name+'" AND `tabSales Person`.%(key)s LIKE "%s" ORDER BY `tabSales Person`.`name` ASC LIMIT 50'; } cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = function(doc, cdt, cdn) { - return 'SELECT `tabItem Group`.name FROM `tabItem Group` WHERE `tabItem Group`.is_group="No" AND `tabItem Group`.docstatus != 2 AND `tabItem Group`.%(key)s LIKE "%s" LIMIT 50' + return{ + filters:{ 'is_group': "No" } + } + // return 'SELECT `tabItem Group`.name FROM `tabItem Group` WHERE `tabItem Group`.is_group="No" AND `tabItem Group`.docstatus != 2 AND `tabItem Group`.%(key)s LIKE "%s" LIMIT 50' } -cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query; \ No newline at end of file +cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.employee_query" } } \ No newline at end of file diff --git a/setup/doctype/territory/territory.js b/setup/doctype/territory/territory.js index 2932006013..3164ba279d 100644 --- a/setup/doctype/territory/territory.js +++ b/setup/doctype/territory/territory.js @@ -30,11 +30,20 @@ cur_frm.cscript.set_root_readonly = function(doc) { //get query select territory cur_frm.fields_dict['parent_territory'].get_query = function(doc,cdt,cdn) { - return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "Yes" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.`name` !="'+doc.territory_name+'" AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50'; + return{ + filters:[ + ['Territory', 'is_group', '=', 'Yes'], + ['Territory', 'name', '!=', doc.territory_name] + ] + } + // return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "Yes" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.`name` !="'+doc.territory_name+'" AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50'; } // ******************** ITEM Group ******************************** cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = function(doc, cdt, cdn) { - return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` FROM `tabItem Group` WHERE `tabItem Group`.is_group="No" AND `tabItem Group`.docstatus != 2 AND `tabItem Group`.%(key)s LIKE "%s" LIMIT 50' + return{ + filters:{ 'is_group': "No"} + } +// return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` FROM `tabItem Group` WHERE `tabItem Group`.is_group="No" AND `tabItem Group`.docstatus != 2 AND `tabItem Group`.%(key)s LIKE "%s" LIMIT 50' } diff --git a/stock/doctype/batch/batch.js b/stock/doctype/batch/batch.js index 93979da5b5..8b26d548cd 100644 --- a/stock/doctype/batch/batch.js +++ b/stock/doctype/batch/batch.js @@ -15,7 +15,10 @@ // along with this program. If not, see . cur_frm.fields_dict['item'].get_query = function(doc, cdt, cdn) { - return erpnext.queries.item({ - 'ifnull(tabItem.is_stock_item, "No")': 'Yes' - }) + return { + query:"controllers.queries.item_query", + filters:{ + 'is_stock_item': 'Yes' + } + } } \ No newline at end of file diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js index 117e77eacb..1ecafd10b3 100644 --- a/stock/doctype/delivery_note/delivery_note.js +++ b/stock/doctype/delivery_note/delivery_note.js @@ -104,12 +104,12 @@ cur_frm.cscript.new_contact = function(){ // ***************** Get project name ***************** cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) { - var cond = ''; - if(doc.customer) cond = '(`tabProject`.customer = "'+doc.customer+'" OR IFNULL(`tabProject`.customer,"")="") AND'; - return repl('SELECT `tabProject`.name FROM `tabProject` \ - WHERE `tabProject`.status not in ("Completed", "Cancelled") \ - AND %(cond)s `tabProject`.name LIKE "%s" \ - ORDER BY `tabProject`.name ASC LIMIT 50', {cond:cond}); + return { + query: "controllers.queries.get_project_name", + filters: { + 'customer': doc.customer + } + } } cur_frm.cscript.serial_no = function(doc, cdt, cdn) { @@ -120,7 +120,9 @@ cur_frm.cscript.serial_no = function(doc, cdt, cdn) { } cur_frm.fields_dict['transporter_name'].get_query = function(doc) { - return 'SELECT DISTINCT `tabSupplier`.`name` FROM `tabSupplier` WHERE `tabSupplier`.supplier_type = "transporter" AND `tabSupplier`.docstatus != 2 AND `tabSupplier`.%(key)s LIKE "%s" ORDER BY `tabSupplier`.`name` LIMIT 50'; + return{ + filters: { 'supplier_type': "transporter" } + } } cur_frm.cscript['Make Packing Slip'] = function() { @@ -133,7 +135,9 @@ cur_frm.cscript['Make Packing Slip'] = 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{ + filters: { 'is_group': "No" } + } } var set_print_hide= function(doc, cdt, cdn){ @@ -221,11 +225,11 @@ if (sys_defaults.auto_inventory_accounting) { // expense account cur_frm.fields_dict['delivery_note_details'].grid.get_field('expense_account').get_query = function(doc) { return { - "query": "accounts.utils.get_account_list", - "filters": { + filters: { "is_pl_account": "Yes", "debit_or_credit": "Debit", - "company": doc.company + "company": doc.company, + "group_or_ledger": "Ledger" } } } @@ -244,8 +248,10 @@ if (sys_defaults.auto_inventory_accounting) { cur_frm.fields_dict.delivery_note_details.grid.get_field("cost_center").get_query = function(doc) { return { - query: "accounts.utils.get_cost_center_list", - filters: { company_name: doc.company} + filters: { + 'company_name': doc.company, + 'group_or_ledger': "Ledger" + } } } } \ No newline at end of file diff --git a/stock/doctype/item/item.js b/stock/doctype/item/item.js index 7a731d28ec..a0937fb285 100644 --- a/stock/doctype/item/item.js +++ b/stock/doctype/item/item.js @@ -51,39 +51,65 @@ cur_frm.cscript.item_code = function(doc) { cur_frm.fields_dict['default_bom'].get_query = function(doc) { //var d = locals[this.doctype][this.docname]; - return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + doc.item_code + '" AND ifnull(`tabBOM`.`is_active`, 0) = 0 and `tabBOM`.docstatus != 2 AND `tabBOM`.%(key)s LIKE "%s" ORDER BY `tabBOM`.`name` LIMIT 50' + return{ + filters:{ + 'item': doc.item_code, + 'is_active': 0 + } + } + // return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + doc.item_code + '" AND ifnull(`tabBOM`.`is_active`, 0) = 0 and `tabBOM`.docstatus != 2 AND `tabBOM`.%(key)s LIKE "%s" ORDER BY `tabBOM`.`name` LIMIT 50' } // Expense Account // --------------------------------- cur_frm.fields_dict['purchase_account'].get_query = function(doc){ - return 'SELECT DISTINCT `tabAccount`.`name` FROM `tabAccount` WHERE `tabAccount`.`debit_or_credit`="Debit" AND `tabAccount`.`group_or_ledger`="Ledger" AND `tabAccount`.`docstatus`!=2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.`name` LIMIT 50' + return{ + filters:{ + 'debit_or_credit': "Debit", + 'group_or_ledger': "Ledger" + } + } } // Income Account // -------------------------------- cur_frm.fields_dict['default_income_account'].get_query = function(doc) { - return 'SELECT DISTINCT `tabAccount`.`name` FROM `tabAccount` WHERE `tabAccount`.`debit_or_credit`="Credit" AND `tabAccount`.`group_or_ledger`="Ledger" AND `tabAccount`.`docstatus`!=2 AND `tabAccount`.`account_type` ="Income Account" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.`name` LIMIT 50' + return{ + filters:{ + 'debit_or_credit': "Credit", + 'group_or_ledger': "Ledger", + 'account_type': "Income Account" + } + } } // Purchase Cost Center // ----------------------------- cur_frm.fields_dict['cost_center'].get_query = function(doc) { - return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.`docstatus`!= 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50' + return{ + filters:{ 'group_or_ledger': "Ledger" } + } } // Sales Cost Center // ----------------------------- cur_frm.fields_dict['default_sales_cost_center'].get_query = function(doc) { - return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.`docstatus`!= 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50' + return{ + filters:{ 'group_or_ledger': "Ledger" } + } } cur_frm.fields_dict['item_tax'].grid.get_field("tax_type").get_query = function(doc, cdt, cdn) { - return 'SELECT `tabAccount`.`name` FROM `tabAccount` WHERE `tabAccount`.`account_type` in ("Tax", "Chargeable") and `tabAccount`.`docstatus` != 2 and `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.`name` DESC LIMIT 50' + return{ + filters:[ + ['Account', 'account_type', 'in', 'Tax, Chargeable'], + ['Account', 'docstatus', '!=', 2] + ] + } } cur_frm.cscript.tax_type = function(doc, cdt, cdn){ @@ -94,10 +120,11 @@ cur_frm.cscript.tax_type = function(doc, cdt, cdn){ //get query select item group cur_frm.fields_dict['item_group'].get_query = function(doc,cdt,cdn) { - return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` \ - FROM `tabItem Group` WHERE `tabItem Group`.`docstatus`!= 2 AND \ - `tabItem Group`.%(key)s LIKE "%s" ORDER BY `tabItem Group`.`name` \ - ASC LIMIT 50' + return { + filters: [ + ['Item Group', 'docstatus', '!=', 2] + ] + } } // for description from attachment @@ -137,10 +164,12 @@ cur_frm.fields_dict['ref_rate_details'].grid.onrowadd = function(doc, cdt, cdn){ } cur_frm.fields_dict.item_customer_details.grid.get_field("customer_name").get_query = - erpnext.utils.customer_query; +function(doc,cdt,cdn) { + return{ query:"controllers.queries.customer_query" } } cur_frm.fields_dict.item_supplier_details.grid.get_field("supplier").get_query = - erpnext.utils.supplier_query; + function(doc,cdt,cdn) { + return{ query:"controllers.queries.supplier_query" } } cur_frm.cscript.on_remove_attachment = function(doc) { if(!inList(cur_frm.fields_dict.image.df.options.split("\n"), doc.image)) { diff --git a/stock/doctype/landed_cost_wizard/landed_cost_wizard.js b/stock/doctype/landed_cost_wizard/landed_cost_wizard.js index eb0c3df0a3..86787cac65 100644 --- a/stock/doctype/landed_cost_wizard/landed_cost_wizard.js +++ b/stock/doctype/landed_cost_wizard/landed_cost_wizard.js @@ -20,5 +20,13 @@ if(!doc.currency){doc.currency = sys_defaults.currency;} cur_frm.fields_dict['landed_cost_details'].grid.get_field("account_head").get_query = function(doc,cdt,cdn) { - return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND (tabAccount.account_type = "Tax" OR tabAccount.account_type = "Chargeable" or (tabAccount.is_pl_account = "Yes" and tabAccount.debit_or_credit = "Debit")) AND tabAccount.name LIKE "%s"'; +return{ + filters:[ + ['Account', 'group_or_ledger', '=', 'Ledger'], + ['Account', 'account_type', 'in', 'Tax, Chargeable'], + ['Account', 'is_pl_account', '=', 'Yes'], + ['Account', 'debit_or_credit', '=', 'Debit'] + ] + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND (tabAccount.account_type = "Tax" OR tabAccount.account_type = "Chargeable" or (tabAccount.is_pl_account = "Yes" and tabAccount.debit_or_credit = "Debit")) AND tabAccount.name LIKE "%s"'; } diff --git a/stock/doctype/packing_slip/packing_slip.js b/stock/doctype/packing_slip/packing_slip.js index 18a248660d..b658220a1c 100644 --- a/stock/doctype/packing_slip/packing_slip.js +++ b/stock/doctype/packing_slip/packing_slip.js @@ -15,17 +15,19 @@ // along with this program. If not, see . cur_frm.fields_dict['delivery_note'].get_query = function(doc, cdt, cdn) { - return 'SELECT name FROM `tabDelivery Note` WHERE docstatus=0 AND %(key)s LIKE "%s"'; + return{ + filters:{ 'docstatus': 0} + } + // return 'SELECT name FROM `tabDelivery Note` WHERE docstatus=0 AND %(key)s LIKE "%s"'; } cur_frm.fields_dict['item_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) { - var query = 'SELECT name, item_name, description FROM `tabItem` WHERE name IN ( \ - SELECT item_code FROM `tabDelivery Note Item` dnd \ - WHERE parent="' + doc.delivery_note + '" AND IFNULL(qty, 0) > IFNULL(packed_qty, 0)) \ - AND %(key)s LIKE "%s" LIMIT 50'; - return query; + return { + query: "stock.doctype.packing_slip.packing_slip.item_details", + filters:{ 'delivery_note': doc.delivery_note} + } } cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { diff --git a/stock/doctype/packing_slip/packing_slip.py b/stock/doctype/packing_slip/packing_slip.py index 1375108fa8..a46d77c696 100644 --- a/stock/doctype/packing_slip/packing_slip.py +++ b/stock/doctype/packing_slip/packing_slip.py @@ -171,4 +171,13 @@ class DocType: ch.item_name = item.item_name ch.stock_uom = item.stock_uom ch.qty = flt(item.qty) - flt(item.packed_qty) - self.update_item_details() \ No newline at end of file + self.update_item_details() + +def item_details(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + return webnotes.conn.sql("""select name, item_name, description from `tabItem` + where name in ( select item_code FROM `tabDelivery Note Item` + where parent= %s and ifnull(qty, 0) > ifnull(packed_qty, 0)) + and %s like "%s" %s limit %s, %s """ % ("%s", searchfield, "%s", + get_match_cond(doctype, searchfield), "%s", "%s"), + (filters["delivery_note"], "%%%s%%" % txt, start, page_len)) \ No newline at end of file diff --git a/stock/doctype/purchase_receipt/purchase_receipt.js b/stock/doctype/purchase_receipt/purchase_receipt.js index 852a9c6079..e21d6a3465 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/stock/doctype/purchase_receipt/purchase_receipt.js @@ -116,11 +116,15 @@ cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc } cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; + return{ + filters:{ 'supplier': doc.supplier} + } } 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 supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; + return{ + filters:{ 'supplier': doc.supplier} + } } cur_frm.cscript.new_contact = function(){ @@ -131,15 +135,19 @@ cur_frm.cscript.new_contact = function(){ } cur_frm.fields_dict['purchase_receipt_details'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) { - return 'SELECT `tabProject`.name FROM `tabProject` \ - WHERE `tabProject`.status not in ("Completed", "Cancelled") \ - AND `tabProject`.name LIKE "%s" ORDER BY `tabProject`.name ASC LIMIT 50'; + return{ + filters:[ + ['project', 'status', 'not in', 'Completed, Cancelled'] + ] + } } cur_frm.fields_dict['purchase_receipt_details'].grid.get_field('batch_no').get_query= function(doc, cdt, cdn) { var d = locals[cdt][cdn]; if(d.item_code){ - return "SELECT tabBatch.name, tabBatch.description FROM tabBatch WHERE tabBatch.docstatus != 2 AND tabBatch.item = '"+ d.item_code +"' AND `tabBatch`.`name` like '%s' ORDER BY `tabBatch`.`name` DESC LIMIT 50" + return{ + filters:{'item': d.item_code} + } } else{ alert("Please enter Item Code."); @@ -156,11 +164,19 @@ cur_frm.cscript.select_print_heading = 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'; + return{ + filters:[ + ['Print Heading', 'docstatus', '!=', '2'] + ] + } } cur_frm.fields_dict.purchase_receipt_details.grid.get_field("qa_no").get_query = function(doc) { - return 'SELECT `tabQuality Inspection`.name FROM `tabQuality Inspection` WHERE `tabQuality Inspection`.docstatus = 1 AND `tabQuality Inspection`.%(key)s LIKE "%s"'; + return { + filters: { + 'docstatus': 1 + } + } } cur_frm.cscript.on_submit = function(doc, cdt, cdn) { diff --git a/stock/doctype/serial_no/serial_no.js b/stock/doctype/serial_no/serial_no.js index 9e1426c6a4..df7058a951 100644 --- a/stock/doctype/serial_no/serial_no.js +++ b/stock/doctype/serial_no/serial_no.js @@ -46,7 +46,10 @@ cur_frm.add_fetch('customer', 'territory', 'territory') // 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{ + filters:{'is_group': "No"} + } + // 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'; } // Supplier @@ -59,11 +62,22 @@ cur_frm.cscript.supplier = function(doc,dt,dn) { //item code //---------- cur_frm.fields_dict['item_code'].get_query = function(doc,cdt,cdn) { - return erpnext.queries.item({ - 'ifnull(tabItem.has_serial_no, "No")': 'Yes' - }); + return{ + query:"controllers.queries.item_query", + filters:{ + 'has_serial_no': 'Yes' + } + } } -cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.customer_query" + } +} -cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query; \ No newline at end of file +cur_frm.fields_dict.supplier.get_query = function(doc,cdt,cdn) { + return{ + query:"controllers.queries.supplier_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 1f4aafa9e5..1a4c225328 100644 --- a/stock/doctype/stock_entry/stock_entry.js +++ b/stock/doctype/stock_entry/stock_entry.js @@ -56,7 +56,9 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ this.frm.fields_dict.delivery_note_no.get_query; this.frm.fields_dict.purchase_receipt_no.get_query = function() { - return { query: "stock.doctype.stock_entry.stock_entry.query_purchase_return_doc" }; + return { + filters:{ 'docstatus': 1 } + }; }; this.frm.fields_dict.mtn_details.grid.get_field('item_code').get_query = function() { @@ -81,8 +83,10 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ this.frm.fields_dict["expense_adjustment_account"].get_query = function() { return { - "query": "accounts.utils.get_account_list", - "filters": { "company": me.frm.doc.company } + filters: { + "company": me.frm.doc.company, + "group_or_ledger": "Ledger" + } } } } @@ -278,9 +282,12 @@ cur_frm.cscript.supplier = function(doc,cdt,cdn){ } cur_frm.fields_dict['production_order'].get_query = function(doc) { - return 'select name from `tabProduction Order` \ - where docstatus = 1 and qty > ifnull(produced_qty,0) AND %(key)s like "%s%%" \ - order by name desc limit 50'; + return{ + filters:[ + ['Production Order', 'docstatus', '=', 1], + ['Production Order', 'qty', '>','`tabProduction Order`.produced_qty'] + ] + } } cur_frm.cscript.purpose = function(doc, cdt, cdn) { @@ -305,17 +312,21 @@ cur_frm.fields_dict['mtn_details'].grid.get_field('batch_no').get_query = functi var d = locals[cdt][cdn]; if(d.item_code) { if (d.s_warehouse) { - return "select batch_no from `tabStock Ledger Entry` sle \ - where item_code = '" + d.item_code + "' and warehouse = '" + d.s_warehouse + - "' and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%s' \ - and exists(select * from `tabBatch` where \ - name = sle.batch_no and expiry_date >= '" + doc.posting_date + - "' and docstatus != 2) group by batch_no having sum(actual_qty) > 0 \ - order by batch_no desc limit 50"; + return{ + query: "stock.doctype.stock_entry.stock_entry.get_batch_no", + filters:{ + 'item_code': d.item_code, + 's_warehouse': d.s_warehouse, + 'posting_date': doc.posting_date + } + } } else { - return "SELECT name FROM tabBatch WHERE docstatus != 2 AND item = '" + - d.item_code + "' and expiry_date >= '" + doc.posting_date + - "' AND name like '%s' ORDER BY name DESC LIMIT 50"; + return{ + filters:[ + ['Batch', 'item', '=', d.item_code], + ['Batch', 'expiry_date', '>=', doc.posting_date] + ] + } } } else { msgprint("Please enter Item Code to get batch no"); @@ -372,6 +383,8 @@ cur_frm.cscript.validate_items = function(doc) { } } -cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.customer_query" } } -cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query; \ No newline at end of file +cur_frm.fields_dict.supplier.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.supplier_query" } } \ No newline at end of file diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index c8babffad9..fc4fadcf18 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -25,6 +25,7 @@ from webnotes.model.code import get_obj from webnotes import msgprint, _ from stock.utils import get_incoming_rate from stock.stock_ledger import get_previous_sle +from controllers.queries import get_match_cond import json sql = webnotes.conn.sql @@ -709,24 +710,29 @@ def get_production_order_details(production_order): return result and result[0] or {} def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond conditions = "" if doctype == "Sales Invoice": conditions = "and update_stock=1" return webnotes.conn.sql("""select name, customer, customer_name from `tab%s` where docstatus = 1 - and (`%s` like %%(txt)s or `customer` like %%(txt)s) %s + and (`%s` like %%(txt)s or `customer` like %%(txt)s) %s %s order by name, customer, customer_name - limit %s""" % (doctype, searchfield, conditions, "%(start)s, %(page_len)s"), - {"txt": "%%%s%%" % txt, "start": start, "page_len": page_len}, as_list=True) + limit %s""" % (doctype, searchfield, conditions, + get_match_cond(doctype, searchfield), "%(start)s, %(page_len)s"), + {"txt": "%%%s%%" % txt, "start": start, "page_len": page_len}, + as_list=True) def query_purchase_return_doc(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond return webnotes.conn.sql("""select name, supplier, supplier_name from `tab%s` where docstatus = 1 - and (`%s` like %%(txt)s or `supplier` like %%(txt)s) + and (`%s` like %%(txt)s or `supplier` like %%(txt)s) %s order by name, supplier, supplier_name - limit %s""" % (doctype, searchfield, "%(start)s, %(page_len)s"), - {"txt": "%%%s%%" % txt, "start": start, "page_len": page_len}, as_list=True) + limit %s""" % (doctype, searchfield, get_match_cond(doctype, searchfield), + "%(start)s, %(page_len)s"), {"txt": "%%%s%%" % txt, "start": + start, "page_len": page_len}, as_list=True) def query_return_item(doctype, txt, searchfield, start, page_len, filters): txt = txt.replace("%", "") @@ -752,6 +758,20 @@ def query_return_item(doctype, txt, searchfield, start, page_len, filters): return result[start:start+page_len] +def get_batch_no(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + + return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle + where item_code = '%(item_code)s' and warehouse = '%(s_warehouse)s' + and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%(txt)s' + and exists(select * from `tabBatch` where name = sle.batch_no + and expiry_date >= %(posting_date)s and docstatus != 2) %(mcond)s + group by batch_no having sum(actual_qty) > 0 + order by batch_no desc limit %(start)s, %(page_len)s """ + % {'item_code': filters['item_code'], 's_warehouse': filters['s_warehouse'], + 'posting_date': filters['posting_date'], 'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield),"start": start, "page_len": page_len}) + def get_stock_items_for_return(ref_doclist, parentfields): """return item codes filtered from doclist, which are stock items""" if isinstance(parentfields, basestring): diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.js b/stock/doctype/stock_reconciliation/stock_reconciliation.js index dd496833b5..b003e05745 100644 --- a/stock/doctype/stock_reconciliation/stock_reconciliation.js +++ b/stock/doctype/stock_reconciliation/stock_reconciliation.js @@ -46,9 +46,9 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ this.frm.fields_dict["expense_account"].get_query = function() { return { - "query": "accounts.utils.get_account_list", "filters": { - "company": me.frm.doc.company + 'company': me.frm.doc.company, + 'group_or_ledger': 'Ledger' } } } diff --git a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.js b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.js index e022bb7c9a..94b3bf0a7b 100644 --- a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.js +++ b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.js @@ -15,7 +15,9 @@ // along with this program. If not, see . cur_frm.fields_dict['item_code'].get_query = function(doc) { - return erpnext.queries.item_std(); + return { + query: "controllers.queries.item_std" + } } //==================== Get Items Stock UOM ===================================================== diff --git a/support/doctype/customer_issue/customer_issue.js b/support/doctype/customer_issue/customer_issue.js index 558ef321b4..1f68602684 100644 --- a/support/doctype/customer_issue/customer_issue.js +++ b/support/doctype/customer_issue/customer_issue.js @@ -65,24 +65,34 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc } cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer + - '" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; + return{ + filters:{ 'customer': doc.customer} + } + // return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer + + // '" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; } 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'; + return{ + filters:{ 'customer': doc.customer} + } + // 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['serial_no'].get_query = function(doc, cdt, cdn) { - var cond = ''; - if(doc.item_code) cond = ' AND `tabSerial No`.item_code = "'+ doc.item_code +'"'; - if(doc.customer) cond += ' AND `tabSerial No`.customer = "' + doc.customer + '"'; - return 'SELECT `tabSerial No`.name, `tabSerial No`.description \ - FROM `tabSerial No` \ - WHERE `tabSerial No`.docstatus != 2 AND `tabSerial No`.status = "Delivered" \ - AND `tabSerial No`.name LIKE "%s" ' + cond + ' ORDER BY `tabSerial No`.name ASC LIMIT 50'; + var cond = []; + var filter = [ + ['Serial No', 'docstatus', '!=', 2], + ['Serial No', 'status', '=', "Delivered"] + ]; + if(doc.item_code) cond = ['Serial No', 'item_code', '=', doc.item_code]; + if(doc.customer) cond = ['Serial No', 'customer', '=', doc.customer]; + filter.push(cond); + return{ + filters:filter + } } cur_frm.add_fetch('serial_no', 'item_code', 'item_code'); @@ -97,15 +107,23 @@ cur_frm.add_fetch('serial_no', 'delivery_address', 'customer_address'); cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { if(doc.serial_no) { - return 'SELECT `tabSerial No`.item_code, `tabSerial No`.description \ - FROM `tabSerial No` \ - WHERE `tabSerial No`.docstatus != 2 AND `tabSerial No`.name = "' + doc.serial_no + - '" AND `tabSerial No`.item_code LIKE "%s" ORDER BY `tabSerial No`.item_code ASC LIMIT 50'; + return{ + filters:{ 'serial_no': doc.serial_no} + } + // return 'SELECT `tabSerial No`.item_code, `tabSerial No`.description \ + // FROM `tabSerial No` \ + // WHERE `tabSerial No`.docstatus != 2 AND `tabSerial No`.name = "' + doc.serial_no + + // '" AND `tabSerial No`.item_code LIKE "%s" ORDER BY `tabSerial No`.item_code ASC LIMIT 50'; } else{ - return 'SELECT `tabItem`.name, `tabItem`.item_name, `tabItem`.description \ - FROM `tabItem` \ - WHERE `tabItem`.docstatus != 2 AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.name ASC LIMIT 50'; + return{ + filters:[ + ['Item', 'docstatus', '!=', 2] + ] + } + // return 'SELECT `tabItem`.name, `tabItem`.item_name, `tabItem`.description \ + // FROM `tabItem` \ + // WHERE `tabItem`.docstatus != 2 AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.name ASC LIMIT 50'; } } @@ -113,10 +131,14 @@ cur_frm.add_fetch('item_code', 'item_name', 'item_name'); cur_frm.add_fetch('item_code', 'description', 'description'); 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{ + filters:{ 'is_group': "No"} + } + // 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 +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.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 ec75289290..a4f954bfe5 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.js +++ b/support/doctype/maintenance_schedule/maintenance_schedule.js @@ -62,16 +62,22 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc } cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; + return{ + filters:{ 'customer': doc.customer} + } } 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'; + return{ + filters:{ 'customer': doc.customer} + } } // cur_frm.fields_dict['item_maintenance_detail'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) { - return 'SELECT tabItem.name,tabItem.item_name,tabItem.description FROM tabItem WHERE tabItem.is_service_item="Yes" AND tabItem.docstatus != 2 AND tabItem.%(key)s LIKE "%s" LIMIT 50'; + return{ + filters:{ 'is_service_item': "Yes"} + } } cur_frm.cscript.item_code = function(doc, cdt, cdn) { @@ -88,7 +94,13 @@ cur_frm.fields_dict['sales_order_no'].get_query = function(doc) { if(doc.customer) { cond = '`tabSales Order`.customer = "'+doc.customer+'" AND'; } - return repl('SELECT DISTINCT `tabSales Order`.name FROM `tabSales Order`, `tabSales Order Item`, `tabItem` WHERE `tabSales Order`.company = "%(company)s" AND `tabSales Order`.docstatus = 1 AND `tabSales Order Item`.parent = `tabSales Order`.name AND `tabSales Order Item`.item_code = `tabItem`.name AND `tabItem`.is_service_item = "Yes" AND %(cond)s `tabSales Order`.name LIKE "%s" ORDER BY `tabSales Order`.name DESC LIMIT 50', {company:doc.company, cond:cond}); + return{ + query:"support.doctype.maintenance_schedule.maintenance_schedule.get_sales_order_no", + filters: { + 'cond': cond, + 'company': doc.company + } + } } cur_frm.cscript.periodicity = function(doc, cdt, cdn){ @@ -118,7 +130,10 @@ 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'; + return{ + filters:{ 'is_group': "No"} + } } -cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.customer_query" } } \ No newline at end of file diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.py b/support/doctype/maintenance_schedule/maintenance_schedule.py index ee7f45a852..6260acd74b 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -331,4 +331,16 @@ def make_maintenance_visit(source_name, target_doclist=None): } }, target_doclist) - return [d.fields for d in doclist] \ No newline at end of file + return [d.fields for d in doclist] +def get_sales_order_no(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + + return webnotes.conn.sql(""" select distinct `tabSales Order`.name from `tabSales Order`, + `tabSales Order Item`, `tabItem` + where `tabSales Order`.company = "%(company)s" and `tabSales Order`.docstatus = 1 + and `tabSales Order Item`.parent = `tabSales Order`.name + and `tabSales Order Item`.item_code = `tabItem`.name + and `tabItem`.is_service_item = "Yes" and %(cond)s `tabSales Order`.name LIKE "%(txt)s" %(mcond)s + ORDER BY `tabSales Order`.name desc LIMIT %(start)s, %(page_len)s""" + % 'company': filters["company"], 'cond': filters['cond'], 'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield), "start": start, "page_len": page_len}) \ 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 6c282c01ad..f803917489 100644 --- a/support/doctype/maintenance_visit/maintenance_visit.js +++ b/support/doctype/maintenance_visit/maintenance_visit.js @@ -77,11 +77,15 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc } cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; + return{ + filters:{'customer': doc.customer} + } } 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'; + return{ + filters:{'customer': doc.customer} + } } cur_frm.cscript.get_items = function(doc, dt, dn) { @@ -93,7 +97,9 @@ cur_frm.cscript.get_items = function(doc, dt, dn) { } cur_frm.fields_dict['maintenance_visit_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) { - return 'SELECT tabItem.name,tabItem.item_name,tabItem.description FROM tabItem WHERE tabItem.is_service_item="Yes" AND tabItem.docstatus != 2 AND tabItem.%(key)s LIKE "%s" LIMIT 50'; + return{ + filters:{ 'is_service_item': "Yes"} + } } cur_frm.cscript.item_code = function(doc, cdt, cdn) { @@ -110,30 +116,52 @@ cur_frm.fields_dict['sales_order_no'].get_query = function(doc) { if(doc.customer) { cond = '`tabSales Order`.customer = "'+doc.customer+'" AND'; } - return repl('SELECT DISTINCT `tabSales Order`.name FROM `tabSales Order`, `tabSales Order Item`, `tabItem` WHERE `tabSales Order`.company = "%(company)s" AND `tabSales Order`.docstatus = 1 AND `tabSales Order Item`.parent = `tabSales Order`.name AND `tabSales Order Item`.item_code = `tabItem`.name AND `tabItem`.is_service_item = "Yes" AND %(cond)s `tabSales Order`.name LIKE "%s" ORDER BY `tabSales Order`.name DESC LIMIT 50', {company:doc.company, cond:cond}); + return{ + query:"support.doctype.maintenance_schedule.maintenance_schedule.get_sales_order_no", + filters: { + 'cond': cond, + 'company': doc.company + } + } } cur_frm.fields_dict['customer_issue_no'].get_query = function(doc) { doc = locals[this.doctype][this.docname]; - var cond = ''; - if(doc.customer) { - cond = '`tabCustomer Issue`.customer = "'+doc.customer+'" AND'; - } - return repl('SELECT `tabCustomer Issue`.name FROM `tabCustomer Issue` WHERE `tabCustomer Issue`.company = "%(company)s" AND %(cond)s `tabCustomer Issue`.docstatus = 1 AND (`tabCustomer Issue`.status = "Open" OR `tabCustomer Issue`.status = "Work In Progress") AND `tabCustomer Issue`.name LIKE "%s" ORDER BY `tabCustomer Issue`.name DESC LIMIT 50', {company:doc.company, cond:cond}); + var cond = []; + var filter = [ + ['Customer Issue', 'company', '=', doc.company], + ['Customer Issue', 'docstatus', '=', 1], + ['Customer Issue', 'status', 'in', 'Open, Work In Progress'] + ]; + if(doc.customer) cond = ['Customer Issue', 'customer', '=', doc.customer]; + filter.push(cond); + return { + filters:filter + } } cur_frm.fields_dict['maintenance_schedule'].get_query = function(doc) { doc = locals[this.doctype][this.docname]; - var cond = ''; - if(doc.customer) { - cond = '`tabMaintenance Schedule`.customer = "'+doc.customer+'" AND'; - } - return repl('SELECT `tabMaintenance Schedule`.name FROM `tabMaintenance Schedule` WHERE `tabMaintenance Schedule`.company = "%(company)s" AND %(cond)s `tabMaintenance Schedule`.docstatus = 1 AND `tabMaintenance Schedule`.name LIKE "%s" ORDER BY `tabMaintenance Schedule`.name DESC LIMIT 50', {company:doc.company, cond:cond}); + var cond = []; + var filter = [ + ['Maintenance Schedule', 'company', '=', doc.company], + ['Maintenance Schedule', 'docstatus', '=', 1] + ]; + if(doc.customer) cond = ['Maintenance Schedule', 'customer', '=', doc.customer]; + filter.push(cond); + return{ + filters:filter + } } //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{ + filters:{ + 'is_group': "No" + } + } } -cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; \ No newline at end of file +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.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 903f41cd58..bd7e6ccf1f 100644 --- a/support/doctype/support_ticket/support_ticket.js +++ b/support/doctype/support_ticket/support_ticket.js @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; +cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.customer_query" } } wn.provide("erpnext.support"); // TODO commonify this code