From 7b4bbbd6bd1dc474257ce262994820e7e16e24ce Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 24 Jun 2013 15:00:21 +0530 Subject: [PATCH 1/9] [reload doctype and page] --- patches/patch_list.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patches/patch_list.py b/patches/patch_list.py index a5c4d805e4..8aba224092 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -19,7 +19,8 @@ patch_list = [ "execute:webnotes.reload_doc('core', 'doctype', 'docfield')", "execute:webnotes.reload_doc('core', 'doctype', 'docperm') # 2013-04-07", "execute:webnotes.reload_doc('core', 'doctype', 'report')", - "execute:webnotes.reload_doc('core', 'doctype', 'doctype')", + "execute:webnotes.reload_doc('core', 'doctype', 'doctype') # 2013-06-24", + "execute:webnotes.reload_doc('core', 'doctype', 'page') # 2013-06-24", "patches.mar_2012.so_rv_mapper_fix", "patches.mar_2012.clean_property_setter", "patches.april_2012.naming_series_patch", From 85cbe16f523b134fc166556a4b06b107a244ab5e Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 24 Jun 2013 15:16:50 +0530 Subject: [PATCH 2/9] [patch] reload sales partner for webpage --- patches/patch_list.py | 1 + 1 file changed, 1 insertion(+) diff --git a/patches/patch_list.py b/patches/patch_list.py index 8aba224092..8d44c08f22 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -201,6 +201,7 @@ patch_list = [ "execute:webnotes.reload_doc('setup', 'doctype', 'item_group') #2013-03-25", "execute:webnotes.reload_doc('website', 'doctype', 'blog_post') #2013-03-25", "execute:webnotes.reload_doc('website', 'doctype', 'web_page') #2013-03-25", + "execute:webnotes.reload_doc('setup', 'doctype', 'sales_partner') #2013-06-24", "execute:webnotes.bean('Style Settings').save() #2013-03-25", "execute:webnotes.conn.set_value('Email Settings', None, 'send_print_in_body_and_attachment', 1)", "patches.march_2013.p09_unset_user_type_partner", From 028755941eeb1d31a5d3672c290caf5b11f22e85 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 8 Jul 2013 18:45:55 +0530 Subject: [PATCH 3/9] get_query to server side --- accounts/doctype/account/account.js | 8 +- accounts/doctype/c_form/c_form.js | 8 +- accounts/doctype/cost_center/cost_center.js | 20 +- .../journal_voucher/journal_voucher.js | 23 ++- .../payment_to_invoice_matching_tool.js | 25 +-- .../payment_to_invoice_matching_tool.py | 16 ++ .../period_closing_voucher.js | 11 +- accounts/doctype/pos_setting/pos_setting.js | 49 ++++- .../purchase_invoice/purchase_invoice.js | 87 +++++++-- .../purchase_taxes_and_charges_master.js | 25 ++- .../doctype/sales_invoice/sales_invoice.js | 135 +++++++++---- .../sales_taxes_and_charges_master.js | 15 +- .../doctype/purchase_order/purchase_order.js | 32 +++- .../quality_inspection/quality_inspection.js | 29 ++- .../supplier_quotation/supplier_quotation.js | 34 ++-- controllers/queries.py | 180 ++++++++++++++++++ manufacturing/doctype/bom/bom.js | 35 ++-- manufacturing/doctype/bom/bom.py | 10 +- 18 files changed, 587 insertions(+), 155 deletions(-) create mode 100644 controllers/queries.py diff --git a/accounts/doctype/account/account.js b/accounts/doctype/account/account.js index c12c2d6964..44f7abd5de 100644 --- a/accounts/doctype/account/account.js +++ b/accounts/doctype/account/account.js @@ -132,7 +132,9 @@ cur_frm.fields_dict['master_name'].get_query = function(doc) { cur_frm.fields_dict['parent_account'].get_query = function(doc) { return { - query: "accounts.doctype.account.account.get_parent_account", - filters: { "company": doc.company} + filters: { + "group_or_ledger": "Group", + "company": doc.company + } } -} +} \ No newline at end of file diff --git a/accounts/doctype/c_form/c_form.js b/accounts/doctype/c_form/c_form.js index d8c7d81f14..35656e9daf 100644 --- a/accounts/doctype/c_form/c_form.js +++ b/accounts/doctype/c_form/c_form.js @@ -18,10 +18,12 @@ // ----------------------------- cur_frm.fields_dict.invoice_details.grid.get_field("invoice_no").get_query = function(doc) { return { - query: "accounts.doctype.c_form.c_form.get_invoice_nos", filters: { - customer: doc.customer, - company: doc.company + "docstatus": 1, + "customer": doc.customer, + "company": doc.company, + "c_form_applicable": 'Yes', + "c_form_no": '' } } } diff --git a/accounts/doctype/cost_center/cost_center.js b/accounts/doctype/cost_center/cost_center.js index 2a98a960c7..094904d6fe 100644 --- a/accounts/doctype/cost_center/cost_center.js +++ b/accounts/doctype/cost_center/cost_center.js @@ -36,11 +36,27 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { //Account filtering for cost center cur_frm.fields_dict['budget_details'].grid.get_field('account').get_query = function(doc) { var mydoc = locals[this.doctype][this.docname]; - return 'SELECT DISTINCT `tabAccount`.`name`,`tabAccount`.debit_or_credit,`tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.`company` = "' + doc.company_name + '" AND `tabAccount`.docstatus != 2 AND `tabAccount`.`is_pl_account` = "Yes" AND `tabAccount`.debit_or_credit = "Debit" AND `tabAccount`.`group_or_ledger` != "Group" AND `tabAccount`.`group_or_ledger` is not NULL AND `tabAccount`.`name` LIKE "%s" ORDER BY `tabAccount`.`name` LIMIT 50'; + return{ + filters:[ + ['Account', 'company', '=', doc.company_name], + ['Account', 'is_pl_account', '=', 'Yes'], + ['Account', 'debit_or_credit', '=', 'Debit'], + ['Account', 'group_or_ledger', '!=', 'Group'], + ['Account', 'group_or_ledger', 'is not', 'NULL'] + ] + } + // return 'SELECT DISTINCT `tabAccount`.`name`,`tabAccount`.debit_or_credit,`tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.`company` = "' + doc.company_name + '" AND `tabAccount`.docstatus != 2 AND `tabAccount`.`is_pl_account` = "Yes" AND `tabAccount`.debit_or_credit = "Debit" AND `tabAccount`.`group_or_ledger` != "Group" AND `tabAccount`.`group_or_ledger` is not NULL AND `tabAccount`.`name` LIKE "%s" ORDER BY `tabAccount`.`name` LIMIT 50'; } cur_frm.fields_dict['parent_cost_center'].get_query = function(doc){ - return 'SELECT DISTINCT `tabCost Center`.name FROM `tabCost Center` WHERE `tabCost Center`.group_or_ledger="Group" AND `tabCost Center`.docstatus != 2 AND `tabCost Center`.company_name="'+ doc.company_name+'" AND `tabCost Center`.company_name is not NULL AND `tabCost Center`.name LIKE "%s" ORDER BY `tabCost Center`.name LIMIT 50'; + return{ + filters:[ + ['Cost Center', 'group_or_ledger', '=', 'Group'], + ['Cost Center', 'company', '=', doc.company_name], + ['Cost Center', 'company_name', 'is not', 'NULL'] + ] + } + // return 'SELECT DISTINCT `tabCost Center`.name FROM `tabCost Center` WHERE `tabCost Center`.group_or_ledger="Group" AND `tabCost Center`.docstatus != 2 AND `tabCost Center`.company_name="'+ doc.company_name+'" AND `tabCost Center`.company_name is not NULL AND `tabCost Center`.name LIKE "%s" ORDER BY `tabCost Center`.name LIMIT 50'; } //parent cost center diff --git a/accounts/doctype/journal_voucher/journal_voucher.js b/accounts/doctype/journal_voucher/journal_voucher.js index dbe666881a..2afea1bce2 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.js +++ b/accounts/doctype/journal_voucher/journal_voucher.js @@ -196,24 +196,35 @@ cur_frm.fields_dict['entries'].grid.get_field('account').get_query = function(do cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc) { return { - query: "accounts.utils.get_cost_center_list", - filters: { company_name: doc.company} + // query: "accounts.utils.get_cost_center_list", + filters: { + 'company_name': doc.company, + 'group_or_ledger': 'Ledger' + } } } cur_frm.fields_dict['entries'].grid.get_field('against_voucher').get_query = function(doc) { var d = locals[this.doctype][this.docname]; return { - query: "accounts.doctype.journal_voucher.journal_voucher.get_against_purchase_invoice", - filters: { account: d.account } + // query: "accounts.doctype.journal_voucher.journal_voucher.get_against_purchase_invoice", + filters: [ + ['Purchase Invoice', 'credit_to', '=', d.account], + ['Purchase Invoice', 'docstatus', '=', 1], + ['Purchase Invoice', 'outstanding_amount', '>', 0] + ] } } cur_frm.fields_dict['entries'].grid.get_field('against_invoice').get_query = function(doc) { var d = locals[this.doctype][this.docname]; return { - query: "accounts.doctype.journal_voucher.journal_voucher.get_against_sales_invoice", - filters: { account: d.account } + // query: "accounts.doctype.journal_voucher.journal_voucher.get_against_sales_invoice", + filters: [ + ['Sales Invoice', 'debit_to', '=', d.account], + ['Sales Invoice', 'docstatus', '=', 1], + ['Sales Invoice', 'outstanding_amount', '>', 0] + ] } } diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js index ac7d9d2d14..ad0c1d0512 100644 --- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js +++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js @@ -36,25 +36,12 @@ cur_frm.fields_dict.voucher_no.get_query = function(doc) { // TO-do: check for pos, it should not come if (!doc.account) msgprint("Please select Account first"); else { - return repl("select gle.voucher_no, gle.posting_date, gle.%(account_type)s \ - from `tabGL Entry` gle \ - where gle.account = '%(acc)s' \ - and gle.voucher_type = '%(dt)s' \ - and gle.voucher_no like '%s' \ - and ifnull(gle.is_cancelled, 'No') = 'No' \ - and (ifnull(gle.against_voucher, '') = '' \ - or ifnull(gle.against_voucher, '') = gle.voucher_no ) \ - and ifnull(gle.%(account_type)s, 0) > 0 \ - and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0) \ - from `tabGL Entry` \ - where against_voucher_type = '%(dt)s' \ - and against_voucher = gle.voucher_no \ - and voucher_no != gle.voucher_no \ - and account = gle.account \ - and ifnull(is_cancelled, 'No') = 'No') != \ - abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)) \ - ORDER BY gle.posting_date DESC, gle.voucher_no DESC LIMIT 50", - {dt:doc.voucher_type, acc:doc.account, account_type: doc.account_type}); + query: "accounts.doctype.payment_to_invoice_matching_tool.payment_to_invoice_matching_tool.gl_entry_details", + filters: { + "dt": doc.voucher_type, + "acc": doc.account, + "account_type": doc.account_type + } } } diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py index ba4dec3715..633bdd1590 100644 --- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py +++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py @@ -139,3 +139,19 @@ class DocType: msgprint("Successfully allocated.") else: msgprint("No amount allocated.", raise_exception=1) + +def gl_entry_details(doctype, txt, searchfield, start, page_len, filters): + ("""select gle.voucher_no, gle.posting_date, gle.%(account_type)s + from `tabGL Entry` gle + where gle.account = '%(acc)s' and gle.voucher_type = '%(dt)s' + and gle.voucher_no like '%s' and ifnull(gle.is_cancelled, 'No') = 'No' + and (ifnull(gle.against_voucher, '') = '' or ifnull(gle.against_voucher, '') = gle.voucher_no ) + and ifnull(gle.%(account_type)s, 0) > 0 + and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0) + from `tabGL Entry` + where against_voucher_type = '%(dt)s' and against_voucher = gle.voucher_no + and voucher_no != gle.voucher_no + and ifnull(is_cancelled, 'No') = 'No') != abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)) + ORDER BY gle.posting_date DESC, gle.voucher_no DESC limit %(start)s, %(page_len)s"""% + {dt:filters["dt"], acc:filters["acc"], account_type: filters['account_type'], "start": start, + "page_len": page_len}) \ No newline at end of file diff --git a/accounts/doctype/period_closing_voucher/period_closing_voucher.js b/accounts/doctype/period_closing_voucher/period_closing_voucher.js index 830092b284..c24f06b2a8 100644 --- a/accounts/doctype/period_closing_voucher/period_closing_voucher.js +++ b/accounts/doctype/period_closing_voucher/period_closing_voucher.js @@ -23,5 +23,14 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { // ***************** Get Account Head ***************** cur_frm.fields_dict['closing_account_head'].get_query = function(doc, cdt, cdn) { - return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.is_pl_account = "No" AND `tabAccount`.debit_or_credit = "Credit" AND `tabAccount`.company = "'+ cstr(doc.company) +'" AND ifnull(`tabAccount`.freeze_account, "No") = "No" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name ASC LIMIT 50'; + return{ + filters:{ + 'is_pl_account': "No", + "debit_or_credit": "Credit", + "company": doc.company, + "freeze_account": "No", + "group_or_ledger": "Ledger" + } + } + // return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.is_pl_account = "No" AND `tabAccount`.debit_or_credit = "Credit" AND `tabAccount`.company = "'+ cstr(doc.company) +'" AND ifnull(`tabAccount`.freeze_account, "No") = "No" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name ASC LIMIT 50'; } diff --git a/accounts/doctype/pos_setting/pos_setting.js b/accounts/doctype/pos_setting/pos_setting.js index 3ba60b4644..a51d93edce 100755 --- a/accounts/doctype/pos_setting/pos_setting.js +++ b/accounts/doctype/pos_setting/pos_setting.js @@ -25,41 +25,74 @@ cur_frm.cscript.onload = function(doc,cdt,cdn){ //cash bank account //------------------------------------ cur_frm.fields_dict['cash_bank_account'].get_query = function(doc,cdt,cdn) { - return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' + return{ + filters:{ + 'debit_or_credit': "Debit", + 'is_pl_account': "No", + 'group_or_ledger': "Ledger", + 'company': doc.company + } + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } // Income Account // -------------------------------- cur_frm.fields_dict['income_account'].get_query = function(doc,cdt,cdn) { - return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.account_type ="Income Account" AND tabAccount.%(key)s LIKE "%s"' + return{ + filters:{ + 'debit_or_credit': "Credit", + 'group_or_ledger': "Ledger", + 'company': doc.company, + 'account_type': "Income Account" + } + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.account_type ="Income Account" AND tabAccount.%(key)s LIKE "%s"' } // Cost Center // ----------------------------- cur_frm.fields_dict['cost_center'].get_query = function(doc,cdt,cdn) { - return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `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:{ + 'company_name': doc.company, + 'group_or_ledger': "Ledger", + } + } + // return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `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'; } //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'; } // ------------------ Get Print Heading ------------------------------------ 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] + ] + } + // return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50'; } cur_frm.fields_dict["expense_account"].get_query = function(doc) { return { - "query": "accounts.utils.get_account_list", - "filters": { + // "query": "accounts.utils.get_account_list", + filters: { "is_pl_account": "Yes", "debit_or_credit": "Debit", - "company": doc.company + "company": doc.company, + "group_or_ledger": "Ledger" } } } diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.js b/accounts/doctype/purchase_invoice/purchase_invoice.js index 0e461f1ba1..1b952ddcbc 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -132,11 +132,17 @@ cur_frm.cscript.make_bank_voucher = function() { 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} + } + // 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'; } 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} + } + // 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'; } cur_frm.fields_dict['entries'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) { @@ -146,32 +152,73 @@ cur_frm.fields_dict['entries'].grid.get_field("item_code").get_query = function( } cur_frm.fields_dict['credit_to'].get_query = function(doc) { - return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.is_pl_account="No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' + return{ + filters:{ + 'debit_or_credit': 'Credit', + 'is_pl_account': 'No', + 'group_or_ledger': 'Ledger', + 'company': doc.company + } + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.is_pl_account="No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } cur_frm.fields_dict['purchase_order_main'].get_query = function(doc) { + var filter = [ + ['Purchase Order', 'docstatus', '=', 1], + ['Purchase Order', 'status', '!=', 'Stopped'], + ['Purchase Order', 'per_billed', '<', 99.99], + ['Purchase Order', 'company', '=', doc.company] + ]; + var cond = []; if (doc.supplier){ - return 'SELECT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 AND `tabPurchase Order`.supplier = "'+ doc.supplier +'" AND `tabPurchase Order`.`status` != "Stopped" AND ifnull(`tabPurchase Order`.`per_billed`,0) < 99.99 AND `tabPurchase Order`.`company` = "' + doc.company + '" AND `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50' - } else { - return 'SELECT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 AND `tabPurchase Order`.`status` != "Stopped" AND ifnull(`tabPurchase Order`.`per_billed`, 0) < 99.99 AND `tabPurchase Order`.`company` = "' + doc.company + '" AND `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50' + cond = ['Purchase Order', 'supplier', '=', doc.supplier]; + // return 'SELECT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 AND `tabPurchase Order`.supplier = "'+ doc.supplier +'" AND `tabPurchase Order`.`status` != "Stopped" AND ifnull(`tabPurchase Order`.`per_billed`,0) < 99.99 AND `tabPurchase Order`.`company` = "' + doc.company + '" AND `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50' + } + filter.push(cond); + return{ + filters: filter } } cur_frm.fields_dict['purchase_receipt_main'].get_query = function(doc) { + var filter = [ + ['Purchase Receipt', 'docstatus', '=', 1], + ['Purchase Receipt', 'status', '!=', 'Stopped'], + ['Purchase Receipt', 'per_billed', '<', 99.99], + ['Purchase Receipt', 'company', '=', doc.company] + ]; + var cond = []; if (doc.supplier){ - return 'SELECT `tabPurchase Receipt`.`name` FROM `tabPurchase Receipt` WHERE `tabPurchase Receipt`.`docstatus` = 1 AND `tabPurchase Receipt`.supplier = "'+ doc.supplier +'" AND `tabPurchase Receipt`.`status` != "Stopped" AND ifnull(`tabPurchase Receipt`.`per_billed`, 0) < 99.99 AND `tabPurchase Receipt`.`company` = "' + doc.company + '" AND `tabPurchase Receipt`.%(key)s LIKE "%s" ORDER BY `tabPurchase Receipt`.`name` DESC LIMIT 50' - } else { - return 'SELECT `tabPurchase Receipt`.`name` FROM `tabPurchase Receipt` WHERE `tabPurchase Receipt`.`docstatus` = 1 AND `tabPurchase Receipt`.`status` != "Stopped" AND ifnull(`tabPurchase Receipt`.`per_billed`, 0) < 99.99 AND `tabPurchase Receipt`.`company` = "' + doc.company + '" AND `tabPurchase Receipt`.%(key)s LIKE "%s" ORDER BY `tabPurchase Receipt`.`name` DESC LIMIT 50' + ['Purchase Receipt', 'supplier', '=', doc.supplier]; + // return 'SELECT `tabPurchase Receipt`.`name` FROM `tabPurchase Receipt` WHERE `tabPurchase Receipt`.`docstatus` = 1 AND `tabPurchase Receipt`.supplier = "'+ doc.supplier +'" AND `tabPurchase Receipt`.`status` != "Stopped" AND ifnull(`tabPurchase Receipt`.`per_billed`, 0) < 99.99 AND `tabPurchase Receipt`.`company` = "' + doc.company + '" AND `tabPurchase Receipt`.%(key)s LIKE "%s" ORDER BY `tabPurchase Receipt`.`name` DESC LIMIT 50' + } + filter.push(cond); + return{ + filters: filter } } // Get Print Heading 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] + ] + } + // return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50'; } cur_frm.fields_dict['entries'].grid.get_field("expense_head").get_query = function(doc) { - return 'SELECT tabAccount.name FROM tabAccount WHERE (tabAccount.debit_or_credit="Debit" OR tabAccount.account_type = "Expense Account") AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'; + return{ + filters:{ + 'debit_or_credit':'Debit', + 'account_type': 'Expense Account', + 'group_or_ledger': 'Ledger', + 'company': doc.company + } + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE (tabAccount.debit_or_credit="Debit" OR tabAccount.account_type = "Expense Account") AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'; } cur_frm.cscript.expense_head = function(doc, cdt, cdn){ var d = locals[cdt][cdn]; @@ -186,8 +233,11 @@ cur_frm.cscript.expense_head = function(doc, cdt, cdn){ cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc) { return { - query: "accounts.utils.get_cost_center_list", - filters: { company_name: doc.company} + // query: "accounts.utils.get_cost_center_list", + filters: { + 'company_name': doc.company, + 'group_or_ledger': 'Ledger' + } } } @@ -228,9 +278,14 @@ cur_frm.cscript.make_jv = function(doc, dt, dn, bank_account) { } cur_frm.fields_dict['entries'].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'] + ] + } + // 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/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js index f04f895baf..e27f0b53e9 100644 --- a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js +++ b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js @@ -127,15 +127,26 @@ cur_frm.cscript.row_id = function(doc, cdt, cdn) { refresh_field('row_id',d.name,'purchase_tax_details'); } -/*---------------------- Get rate if account_head has account_type as TAX or CHARGEABLE-------------------------------------*/ - -cur_frm.fields_dict['purchase_tax_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 in ("Tax", "Chargeable", "Expense Account") or (tabAccount.is_pl_account = "Yes" and tabAccount.debit_or_credit = "Debit")) AND tabAccount.company = "' + doc.company + '" AND tabAccount.name LIKE "%s"' -} - +cur_frm.set_query("account_head", "purchase_tax_details", function() { + return { + filters: [ + ["Account", "group_or_ledger", "=", "Ledger"], + ["Account", "docstatus", "!=", 2], + ["Account", "account_type", "in", "Tax, Chargeable, Expense Account"], + ["Account", "is_pl_account", "=", "Yes"], + ["Account", "debit_or_credit", "=", "Debit"], + ["Account", "company", "=", doc.company] + ] + } +}); cur_frm.fields_dict['purchase_tax_details'].grid.get_field("cost_center").get_query = function(doc) { - return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `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: { + 'company_name': doc.company, + 'group_or_ledger': "Ledger" + } + } } diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index ecfa9a8ffe..2c07eafd8e 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -241,38 +241,75 @@ cur_frm.cscript.make_bank_voucher = function() { } cur_frm.fields_dict.debit_to.get_query = function(doc) { - return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' + return{ + filters: { + 'debit_or_credit': 'Debit', + 'is_pl_account': 'No', + 'group_or_ledger': 'Ledger', + 'company': doc.company + } + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } cur_frm.fields_dict.cash_bank_account.get_query = function(doc) { - return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' + return{ + filters: { + 'debit_or_credit': 'Debit', + 'is_pl_account': 'No', + 'group_or_ledger': 'Ledger', + 'company': doc.company + } + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } cur_frm.fields_dict.write_off_account.get_query = function(doc) { - return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "Yes" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' + return{ + filters:{ + 'debit_or_credit': 'Debit', + 'is_pl_account': 'Yes', + 'group_or_ledger': 'Ledger', + 'company': doc.company + } + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "Yes" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } // Write off cost center //----------------------- cur_frm.fields_dict.write_off_cost_center.get_query = function(doc) { - return 'SELECT `tabCost Center`.name FROM `tabCost Center` WHERE `tabCost Center`.group_or_ledger="Ledger" AND `tabCost Center`.docstatus!=2 AND `tabCost Center`.company_name="'+doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s"' + return{ + filters:{ + 'group_or_ledger': 'Ledger', + 'company_name': doc.company + } + } + // return 'SELECT `tabCost Center`.name FROM `tabCost Center` WHERE `tabCost Center`.group_or_ledger="Ledger" AND `tabCost Center`.docstatus!=2 AND `tabCost Center`.company_name="'+doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s"' } //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} + } + // 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}); } //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'; } // Income Account in Details Table @@ -285,11 +322,12 @@ cur_frm.set_query("income_account", "entries", function(doc) { if (sys_defaults.auto_inventory_accounting) { cur_frm.fields_dict['entries'].grid.get_field('expense_account').get_query = function(doc) { return { - "query": "accounts.utils.get_account_list", - "filters": { - "is_pl_account": "Yes", - "debit_or_credit": "Debit", - "company": doc.company + // "query": "accounts.utils.get_account_list", + filters: { + 'is_pl_account': 'Yes', + 'debit_or_credit': 'Debit', + 'company': doc.company, + 'group_or_ledger': 'Ledger' } } } @@ -299,45 +337,66 @@ if (sys_defaults.auto_inventory_accounting) { //---------------------------- cur_frm.fields_dict['entries'].grid.get_field('warehouse').get_query= function(doc, cdt, cdn) { var d = locals[cdt][cdn]; - return "SELECT `tabBin`.`warehouse`, `tabBin`.`actual_qty` FROM `tabBin` WHERE `tabBin`.`item_code` = '"+ d.item_code +"' AND ifnull(`tabBin`.`actual_qty`,0) > 0 AND `tabBin`.`warehouse` like '%s' ORDER BY `tabBin`.`warehouse` DESC LIMIT 50"; + return{ + filters:[ + ['Bin', 'item_code', '=', d.item_code], + ['Bin', 'actual_qty', '>', 0] + ] + } + // return "SELECT `tabBin`.`warehouse`, `tabBin`.`actual_qty` FROM `tabBin` WHERE `tabBin`.`item_code` = '"+ d.item_code +"' AND ifnull(`tabBin`.`actual_qty`,0) > 0 AND `tabBin`.`warehouse` like '%s' ORDER BY `tabBin`.`warehouse` DESC LIMIT 50"; } // Cost Center in Details Table // ----------------------------- cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc) { return { - query: "accounts.utils.get_cost_center_list", - filters: { company_name: doc.company} + // query: "accounts.utils.get_cost_center_list", + filters: { + 'company_name': doc.company, + 'group_or_ledger': 'Ledger' + } } } // Sales Order // ----------- cur_frm.fields_dict.sales_order_main.get_query = function(doc) { - if (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'; - else - 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`.%(key)s LIKE "%s" ORDER BY `tabSales Order`.`name` DESC LIMIT 50'; + 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) { - if (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'; - else - 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`.%(key)s LIKE "%s" \ - ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50'; + 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 + } } diff --git a/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js b/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js index 5787427339..81a5c709f0 100644 --- a/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js +++ b/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js @@ -137,11 +137,22 @@ cur_frm.cscript.row_id = function(doc, cdt, cdn) { /*---------------------- Get rate if account_head has account_type as TAX or CHARGEABLE-------------------------------------*/ cur_frm.fields_dict['other_charges'].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 in ("Tax", "Chargeable", "Income Account") AND tabAccount.company = "'+doc.company+'" AND tabAccount.name LIKE "%s"' + return{ + filters:[ + ['Account', 'group_or_ledger', '=', 'Ledger'], + ['Account', 'account_type', 'in', 'Tax, Chargeable, Income Account'], + ['Account', 'company', '=', doc.company] + ] + } + // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.account_type in ("Tax", "Chargeable", "Income Account") AND tabAccount.company = "'+doc.company+'" AND tabAccount.name LIKE "%s"' } cur_frm.fields_dict['other_charges'].grid.get_field("cost_center").get_query = function(doc) { - return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `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{ + 'company_name': doc.company, + 'group_or_ledger': "Ledger" + } + // return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `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'; } diff --git a/buying/doctype/purchase_order/purchase_order.js b/buying/doctype/purchase_order/purchase_order.js index 4c2298242c..ae91e39e4a 100644 --- a/buying/doctype/purchase_order/purchase_order.js +++ b/buying/doctype/purchase_order/purchase_order.js @@ -80,25 +80,37 @@ 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} + } + // 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'; } 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} + } + // 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'; } cur_frm.fields_dict['po_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['indent_no'].get_query = function(doc) { - return 'SELECT DISTINCT `name` FROM `tabMaterial Request` \ - WHERE material_request_type="Purchase" and company = "' + doc.company - + '" and `docstatus` = 1 and `status` != "Stopped" \ - and ifnull(`per_ordered`,0) < 99.99 and %(key)s LIKE "%s" \ - ORDER BY `name` DESC LIMIT 50'; + return{ + filters:[ + ['Material Request', 'material_request_type', '=', 'Purchase'], + ['Material Request', 'company', '=', doc.company], + ['Material Request', 'docstatus', '=', '1'], + ['Material Request', 'status', '!=', 'Stopped'], + ['Material Request', 'per_ordered', '<', 99.99] + ] + } } cur_frm.cscript.get_last_purchase_rate = function(doc, cdt, cdn){ diff --git a/buying/doctype/quality_inspection/quality_inspection.js b/buying/doctype/quality_inspection/quality_inspection.js index 2dbb2854fd..1c12f3a8a5 100644 --- a/buying/doctype/quality_inspection/quality_inspection.js +++ b/buying/doctype/quality_inspection/quality_inspection.js @@ -43,18 +43,33 @@ cur_frm.cscript.refresh = cur_frm.cscript.inspection_type; // item code based on GRN/DN cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { + filter = {}; if (doc.purchase_receipt_no) - return 'SELECT item_code, item_name, description FROM `tabPurchase Receipt Item` WHERE parent = "'+ doc.purchase_receipt_no +'" and docstatus != 2 AND item_code LIKE "%s" ORDER BY item_code ASC LIMIT 50'; + filter:{ + 'parent': doc.purchase_receipt_no + } + // return 'SELECT item_code, item_name, description FROM `tabPurchase Receipt Item` WHERE parent = "'+ doc.purchase_receipt_no +'" and docstatus != 2 AND item_code LIKE "%s" ORDER BY item_code ASC LIMIT 50'; else if (doc.delivery_note_no) - return 'SELECT item_code, item_name, description FROM `tabDelivery Note Item` WHERE parent = "'+ doc.delivery_note_no +'" and docstatus != 2 AND item_code LIKE "%s" ORDER BY item_code ASC LIMIT 50'; - else - return 'SELECT name, item_name, description FROM tabItem WHERE docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; + filter:{ + 'parent': doc.delivery_note_no + } + // return 'SELECT item_code, item_name, description FROM `tabDelivery Note Item` WHERE parent = "'+ doc.delivery_note_no +'" and docstatus != 2 AND item_code LIKE "%s" ORDER BY item_code ASC LIMIT 50'; + return{ + filters: filter + } } // Serial No based on item_code cur_frm.fields_dict['item_serial_no'].get_query = function(doc, cdt, cdn) { + filter = {}; if (doc.item_code) - return 'SELECT name, item_code, warehouse FROM `tabSerial No` WHERE docstatus != 2 AND item_code = "' + doc.item_code +'" AND status = "In Store" AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; + filter:{ + 'item_code': doc.item_code, + 'status': "In Store" + } + // return 'SELECT name, item_code, warehouse FROM `tabSerial No` WHERE docstatus != 2 AND item_code = "' + doc.item_code +'" AND status = "In Store" AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; else - return 'SELECT name, item_code, warehouse FROM `tabSerial No` WHERE docstatus != 2 AND status = "In Store" AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; -} + filter:{ 'status': "In Store" } + // return 'SELECT name, item_code, warehouse FROM `tabSerial No` WHERE docstatus != 2 AND status = "In Store" AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; + return{ filters: filter } +} \ No newline at end of file diff --git a/buying/doctype/supplier_quotation/supplier_quotation.js b/buying/doctype/supplier_quotation/supplier_quotation.js index 8ecb6ea230..ffa23d8f4b 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/buying/doctype/supplier_quotation/supplier_quotation.js @@ -56,18 +56,23 @@ cur_frm.cscript.uom = function(doc, cdt, cdn) { cur_frm.fields_dict['quotation_items'].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['indent_no'].get_query = function(doc) { - return "select distinct `name` from `tabMaterial Request` \ - where material_request_type='Purchase' and company = \"" + doc.company + - "\" and `docstatus` = 1 and `status` != \"Stopped\" and \ - ifnull(`per_ordered`,0) < 99.99 and \ - %(key)s LIKE \"%s\" order by `name` desc limit 50"; + return{ + filters:[ + ['Material Request', 'material_request_type', '=', 'Purchase'], + ['Material Request', 'company', '=', doc.company], + ['Material Request', 'docstatus', '=', 1], + ['Material Request', 'status', '!=', 'Stopped'], + ['Material Request', 'per_ordered', '<', 99.99] + ] + } } cur_frm.cscript.supplier_address = function(doc, dt, dn) { @@ -79,12 +84,13 @@ cur_frm.cscript.supplier_address = function(doc, dt, dn) { cur_frm.cscript.contact_person = cur_frm.cscript.supplier_address; 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} + } } diff --git a/controllers/queries.py b/controllers/queries.py new file mode 100644 index 0000000000..896147fb2b --- /dev/null +++ b/controllers/queries.py @@ -0,0 +1,180 @@ + # ERPNext - web based ERP (http://erpnext.com) + # Copyright (C) 2012 Web Notes Technologies Pvt Ltd + + # This program is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + + # You should have received a copy of the GNU General Public License + # along with this program. If not, see . + +from __future__ import unicode_literals +import webnotes + +def get_filters_cond(doctype, filters, conditions): + if filters: + if isinstance(filters, dict): + filters = map(lambda f: [doctype, f[0], "=", f[1]], filters.items()) + + from webnotes.widgets.reportview import build_filter_conditions + build_filter_conditions(filters, conditions) + cond = ' and ' + ' and '.join(conditions) + else: + cond = '' + return cond + +def get_match_cond(doctype, searchfield = 'name'): + meta = webnotes.get_doctype(doctype) + from webnotes.widgets.search import get_std_fields_list + fields = get_std_fields_list(meta, searchfield) + + from webnotes.widgets.reportview import build_match_conditions + cond = build_match_conditions(doctype, fields) + if cond: + cond = ' and ' + cond + else: + cond = '' + return cond + + # searches for enabled profiles +def profile_query(doctype, txt, searchfield, start, page_len, filters): + return webnotes.conn.sql("""select name, concat_ws(' ', first_name, middle_name, last_name) + from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and + name not in ('Administrator', 'Guest') and (%(key)s like "%(txt)s" or + concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s") %(mcond)s + order by + case when name like "%(txt)s" then 0 else 1 end, + case when concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s" + then 0 else 1 end, + 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}) + + # searches for active employees +def employee_query(doctype, txt, searchfield, start, page_len, filters): + return webnotes.conn.sql("""select name, employee_name from `tabEmployee` + where status = 'Active' and docstatus < 2 and + (%(key)s like "%(txt)s" or employee_name like "%(txt)s") %(mcond)s + order by + case when name like "%(txt)s" then 0 else 1 end, + case when employee_name like "%(txt)s" then 0 else 1 end, + name limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) + + # searches for leads which are not converted +def lead_query(doctype, txt, searchfield, start, page_len, filters): + return webnotes.conn.sql("""select name, lead_name, company_name from `tabLead` + where docstatus < 2 and ifnull(status, '') != 'Converted' and + (%(key)s like "%(txt)s" or lead_name like "%(txt)s" or company_name like "%(txt)s") %(mcond)s + order by + case when name like "%(txt)s" then 0 else 1 end, + case when lead_name like "%(txt)s" then 0 else 1 end, + case when company_name like "%(txt)s" then 0 else 1 end, + lead_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}) + + # searches for customer +def customer_query(doctype, txt, searchfield, start, page_len, filters): + cust_master_name = webnotes.defaults.get_user_default("cust_master_name") + if cust_master_name == "Customer Name": + fields = ["name", "customer_group", "territory"] + else: + fields = ["name", "customer_name", "customer_group", "territory"] + fields = ", ".join(fields) + + return webnotes.conn.sql("""select %(field)s from `tabCustomer` where docstatus < 2 and + (%(key)s like "%(txt)s" or customer_name like "%(txt)s") %(mcond)s + order by + case when name like "%(txt)s" then 0 else 1 end, + case when customer_name like "%(txt)s" then 0 else 1 end, + name, customer_name limit %(start)s, %(page_len)s""" % {'field': fields,'key': searchfield, + 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), + 'start': start, 'page_len': page_len}) + +# searches for supplier +def supplier_query(doctype, txt, searchfield, start, page_len, filters): + supp_master_name = webnotes.defaults.get_user_default("supp_master_name") + if supp_master_name == "Supplier Name": + fields = ["name", "supplier_type"] + else: + fields = ["name", "supplier_name", "supplier_type"] + fields = ", ".join(fields) + + return webnotes.conn.sql("""select %(field)s from `tabSupplier` where docstatus < 2 and \ + (%(key)s like "%(txt)s" or supplier_name like "%(txt)s") %(mcond)s + order by + case when name like "%(txt)s" then 0 else 1 end, + case when supplier_name like "%(txt)s" then 0 else 1 end, + name, supplier_name limit %(start)s, %(page_len)s """ % {'field': fields,'key': searchfield, + 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), 'start': start, + 'page_len': page_len}) + +def item_std(doctype, txt, searchfield, start, page_len, filters): + return webnotes.conn.sql("""select tabItem.name, + if(length(tabItem.item_name) > 40, + concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name, + if(length(tabItem.description) > 40, + concat(substr(tabItem.description, 1, 40), "..."), description) as decription + FROM tabItem + WHERE tabItem.docstatus!=2 + AND tabItem.%(key)s LIKE "%(txt)s" %(mcond)s limit %(start)s, %(page_len)s """ % + {'key': searchfield, 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), + 'start': start, 'page_len': page_len}) + +def account_query(doctype, txt, searchfield, start, page_len, filters): + conditions = [] + if not filters: + filters = {} + if not filters.group_or_ledger: + filters.group_or_ledger = "Ledger" + + return webnotes.conn.sql("""select tabAccount.name, tabAccount.parent_account, + tabAccount.debit_or_credit from tabAccount + where tabAccount.docstatus!=2 and tabAccount.%(key)s LIKE "%(txt)s" + %(fcond)s %(mcond)s limit %(start)s, %(page_len)s""" % {'key': searchfield, + 'txt': "%%%s%%" % txt, 'fcond': get_filters_cond(doctype, filters, conditions), + 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) + +def item_query(doctype, txt, searchfield, start, page_len, filters): + conditions = [] + return webnotes.conn.sql("""select tabItem.name, + if(length(tabItem.item_name) > 40, + concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name, + if(length(tabItem.description) > 40, \ + concat(substr(tabItem.description, 1, 40), "..."), description) as decription + FROM tabItem + WHERE tabItem.docstatus!=2 + AND (ifnull(`tabItem`.`end_of_life`,"") in ("", "0000-00-00") + OR `tabItem`.`end_of_life` > NOW()) + AND (tabItem.%(key)s LIKE "%(txt)s" OR tabItem.item_name LIKE "%(txt)s") %(fcond)s + %(mcond)s limit %(start)s,%(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt, + 'fcond': get_filters_cond(doctype, filters, conditions), + 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) + +def bom(doctype, txt, searchfield, start, page_len, filters): + conditions = [] + return webnotes.conn.sql("""select tabBOM.name, tabBOM.item + from tabBOM + where tabBOM.docstatus=1 and tabBOM.is_active=1 + and tabBOM.%(key)s like "%s" %(fcond)s %(mcond)s limit %(start)s, + %(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt, + 'fcond': get_filters_cond(doctype, filters, conditions), 'mcond':get_match_cond(doctype, searchfield), + 'start': start, 'page_len': page_len}) + +# erpnext.queries.task = function() { +# return { query: "projects.utils.query_task" }; +# }; + +def get_project_name(doctype, txt, searchfield, start, page_len, filters): + cond = '' + if filters['customer']: + cond = '(`tabProject`.customer = filter[customer] or ifnull(`tabProject`.customer,"")="") ' + 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 """ % + {'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/manufacturing/doctype/bom/bom.js b/manufacturing/doctype/bom/bom.js index d14590cb08..acb770d2f1 100644 --- a/manufacturing/doctype/bom/bom.js +++ b/manufacturing/doctype/bom/bom.js @@ -169,30 +169,37 @@ var calculate_total = function(doc) { cur_frm.fields_dict['item'].get_query = function(doc) { - return erpnext.queries.item({ - 'ifnull(tabItem.is_manufactured_item, "No")': 'Yes', - }) + return{ + query:"controllers.queries.item_query", + filters:{ + 'has_serial_no': 'Yes' + } + } } 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'] + ] + } } cur_frm.fields_dict['bom_materials'].grid.get_field('item_code').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`.`%(key)s` like "%s" \ - ORDER BY `tabItem`.`name` LIMIT 50'; + return{ + query:"controllers.queries.item_query" + } } cur_frm.fields_dict['bom_materials'].grid.get_field('bom_no').get_query = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; - return 'SELECT DISTINCT `tabBOM`.`name`, `tabBOM`.`remarks` FROM `tabBOM` \ - WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = 1 AND \ - `tabBOM`.docstatus = 1 AND `tabBOM`.`name` like "%s" \ - ORDER BY `tabBOM`.`name` LIMIT 50'; + return{ + filters:{ + 'item': d.item_code, + 'is_active': 1, + 'docstatus': 1 + } + } } cur_frm.cscript.validate = function(doc, dt, dn) { diff --git a/manufacturing/doctype/bom/bom.py b/manufacturing/doctype/bom/bom.py index 5f641486b5..00523c55de 100644 --- a/manufacturing/doctype/bom/bom.py +++ b/manufacturing/doctype/bom/bom.py @@ -85,10 +85,10 @@ class DocType: msgprint("Item %s does not exist in system" % item[0]['item_code'], raise_exception = 1) def set_bom_material_details(self): - for item in self.doclist.get({"parentfield": "bom_materials"}): - ret = self.get_bom_material_detail({ "item_code": item.item_code, "bom_no": item.bom_no, - "qty": item.qty }) - + for item in self.doclist.get({"parentfield": "bom_materials"}): + ret = self.get_bom_material_detail({"item_code": item.item_code, "bom_no": item.bom_no, + "qty": item.qty}) + for r in ret: if not item.fields.get(r): item.fields[r] = ret[r] @@ -100,7 +100,7 @@ class DocType: args = webnotes.form_dict.get('args') import json args = json.loads(args) - + item = self.get_item_det(args['item_code']) self.validate_rm_item(item) From ab462d2000cfd11196214fb7977e2bd22f8fd4ec Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 9 Jul 2013 16:18:52 +0530 Subject: [PATCH 4/9] [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 From 2e3c06e66d06244bd1493c346691ce00d56e2603 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 9 Jul 2013 18:20:49 +0530 Subject: [PATCH 5/9] [get_query]to server side --- accounts/doctype/cost_center/cost_center.js | 4 +- .../journal_voucher/journal_voucher.js | 3 -- .../period_closing_voucher.js | 1 - accounts/doctype/pos_setting/pos_setting.js | 6 --- .../purchase_invoice/purchase_invoice.js | 45 ------------------- .../doctype/sales_invoice/sales_invoice.js | 13 ------ .../sales_taxes_and_charges_master.js | 2 - .../doctype/purchase_order/purchase_order.js | 14 ------ .../quality_inspection/quality_inspection.js | 2 - .../supplier_quotation/supplier_quotation.js | 14 +----- hr/doctype/appraisal/appraisal.js | 4 +- .../salary_structure/salary_structure.js | 4 +- .../production_order/production_order.js | 4 -- projects/doctype/task/task.js | 2 +- projects/doctype/task/task.py | 2 +- selling/doctype/customer/customer.js | 1 - .../installation_note/installation_note.js | 21 +++------ selling/doctype/opportunity/opportunity.js | 8 ---- selling/doctype/quotation/quotation.js | 1 - selling/doctype/sales_bom/sales_bom.js | 3 -- .../authorization_rule/authorization_rule.js | 5 --- setup/doctype/company/company.js | 14 ------ .../contact_control/contact_control.js | 3 +- .../doctype/customer_group/customer_group.js | 4 -- setup/doctype/item_group/item_group.js | 1 - setup/doctype/sales_partner/sales_partner.js | 1 - setup/doctype/sales_person/sales_person.js | 2 - setup/doctype/territory/territory.js | 2 - stock/doctype/item/item.js | 1 - .../landed_cost_wizard/landed_cost_wizard.js | 1 - stock/doctype/packing_slip/packing_slip.js | 1 - stock/doctype/serial_no/serial_no.js | 1 - .../doctype/customer_issue/customer_issue.js | 16 ------- 33 files changed, 13 insertions(+), 193 deletions(-) diff --git a/accounts/doctype/cost_center/cost_center.js b/accounts/doctype/cost_center/cost_center.js index ad3a16237e..d273e53e56 100644 --- a/accounts/doctype/cost_center/cost_center.js +++ b/accounts/doctype/cost_center/cost_center.js @@ -45,8 +45,7 @@ cur_frm.fields_dict['budget_details'].grid.get_field('account').get_query = func ['Account', 'group_or_ledger', 'is not', 'NULL'] ] } - // return 'SELECT DISTINCT `tabAccount`.`name`,`tabAccount`.debit_or_credit,`tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.`company` = "' + doc.company_name + '" AND `tabAccount`.docstatus != 2 AND `tabAccount`.`is_pl_account` = "Yes" AND `tabAccount`.debit_or_credit = "Debit" AND `tabAccount`.`group_or_ledger` != "Group" AND `tabAccount`.`group_or_ledger` is not NULL AND `tabAccount`.`name` LIKE "%s" ORDER BY `tabAccount`.`name` LIMIT 50'; - } +} cur_frm.fields_dict['parent_cost_center'].get_query = function(doc){ return{ @@ -56,7 +55,6 @@ cur_frm.fields_dict['parent_cost_center'].get_query = function(doc){ ['Cost Center', 'company_name', 'is not', 'NULL'] ] } - // return 'SELECT DISTINCT `tabCost Center`.name FROM `tabCost Center` WHERE `tabCost Center`.group_or_ledger="Group" AND `tabCost Center`.docstatus != 2 AND `tabCost Center`.company_name="'+ doc.company_name+'" AND `tabCost Center`.company_name is not NULL AND `tabCost Center`.name LIKE "%s" ORDER BY `tabCost Center`.name LIMIT 50'; } //parent cost center diff --git a/accounts/doctype/journal_voucher/journal_voucher.js b/accounts/doctype/journal_voucher/journal_voucher.js index 2afea1bce2..ea07798178 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.js +++ b/accounts/doctype/journal_voucher/journal_voucher.js @@ -196,7 +196,6 @@ cur_frm.fields_dict['entries'].grid.get_field('account').get_query = function(do cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc) { return { - // query: "accounts.utils.get_cost_center_list", filters: { 'company_name': doc.company, 'group_or_ledger': 'Ledger' @@ -207,7 +206,6 @@ cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = functio cur_frm.fields_dict['entries'].grid.get_field('against_voucher').get_query = function(doc) { var d = locals[this.doctype][this.docname]; return { - // query: "accounts.doctype.journal_voucher.journal_voucher.get_against_purchase_invoice", filters: [ ['Purchase Invoice', 'credit_to', '=', d.account], ['Purchase Invoice', 'docstatus', '=', 1], @@ -219,7 +217,6 @@ cur_frm.fields_dict['entries'].grid.get_field('against_voucher').get_query = fun cur_frm.fields_dict['entries'].grid.get_field('against_invoice').get_query = function(doc) { var d = locals[this.doctype][this.docname]; return { - // query: "accounts.doctype.journal_voucher.journal_voucher.get_against_sales_invoice", filters: [ ['Sales Invoice', 'debit_to', '=', d.account], ['Sales Invoice', 'docstatus', '=', 1], diff --git a/accounts/doctype/period_closing_voucher/period_closing_voucher.js b/accounts/doctype/period_closing_voucher/period_closing_voucher.js index c24f06b2a8..fd45841783 100644 --- a/accounts/doctype/period_closing_voucher/period_closing_voucher.js +++ b/accounts/doctype/period_closing_voucher/period_closing_voucher.js @@ -32,5 +32,4 @@ cur_frm.fields_dict['closing_account_head'].get_query = function(doc, cdt, cdn) "group_or_ledger": "Ledger" } } - // return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.is_pl_account = "No" AND `tabAccount`.debit_or_credit = "Credit" AND `tabAccount`.company = "'+ cstr(doc.company) +'" AND ifnull(`tabAccount`.freeze_account, "No") = "No" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name ASC LIMIT 50'; } diff --git a/accounts/doctype/pos_setting/pos_setting.js b/accounts/doctype/pos_setting/pos_setting.js index b15ec3e04a..aa9cf11539 100755 --- a/accounts/doctype/pos_setting/pos_setting.js +++ b/accounts/doctype/pos_setting/pos_setting.js @@ -33,7 +33,6 @@ cur_frm.fields_dict['cash_bank_account'].get_query = function(doc,cdt,cdn) { 'company': doc.company } } - // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } // Income Account @@ -47,7 +46,6 @@ cur_frm.fields_dict['income_account'].get_query = function(doc,cdt,cdn) { 'account_type': "Income Account" } } - // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.account_type ="Income Account" AND tabAccount.%(key)s LIKE "%s"' } @@ -60,7 +58,6 @@ cur_frm.fields_dict['cost_center'].get_query = function(doc,cdt,cdn) { 'group_or_ledger': "Ledger", } } - // return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `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'; } //get query select Territory @@ -71,7 +68,6 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { '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'; } @@ -82,12 +78,10 @@ cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) ['Print Heading', 'docstatus', '!=', 2] ] } - // return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50'; } cur_frm.fields_dict["expense_account"].get_query = function(doc) { return { - // "query": "accounts.utils.get_account_list", filters: { "is_pl_account": "Yes", "debit_or_credit": "Debit", diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.js b/accounts/doctype/purchase_invoice/purchase_invoice.js index 2e41d70af0..efe0c2a990 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -155,14 +155,12 @@ cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) { return{ filters:{'supplier': doc.supplier} } - // 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'; } cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { return{ filters:{'supplier': doc.supplier} } - // 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'; } cur_frm.fields_dict['entries'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) { @@ -183,43 +181,6 @@ cur_frm.fields_dict['credit_to'].get_query = function(doc) { 'company': doc.company } } - // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.is_pl_account="No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' -} - -cur_frm.fields_dict['purchase_order_main'].get_query = function(doc) { - var filter = [ - ['Purchase Order', 'docstatus', '=', 1], - ['Purchase Order', 'status', '!=', 'Stopped'], - ['Purchase Order', 'per_billed', '<', 99.99], - ['Purchase Order', 'company', '=', doc.company] - ]; - var cond = []; - if (doc.supplier){ - cond = ['Purchase Order', 'supplier', '=', doc.supplier]; - // return 'SELECT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 AND `tabPurchase Order`.supplier = "'+ doc.supplier +'" AND `tabPurchase Order`.`status` != "Stopped" AND ifnull(`tabPurchase Order`.`per_billed`,0) < 99.99 AND `tabPurchase Order`.`company` = "' + doc.company + '" AND `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50' - } - filter.push(cond); - return{ - filters: filter - } -} - -cur_frm.fields_dict['purchase_receipt_main'].get_query = function(doc) { - var filter = [ - ['Purchase Receipt', 'docstatus', '=', 1], - ['Purchase Receipt', 'status', '!=', 'Stopped'], - ['Purchase Receipt', 'per_billed', '<', 99.99], - ['Purchase Receipt', 'company', '=', doc.company] - ]; - var cond = []; - if (doc.supplier){ - ['Purchase Receipt', 'supplier', '=', doc.supplier]; - // return 'SELECT `tabPurchase Receipt`.`name` FROM `tabPurchase Receipt` WHERE `tabPurchase Receipt`.`docstatus` = 1 AND `tabPurchase Receipt`.supplier = "'+ doc.supplier +'" AND `tabPurchase Receipt`.`status` != "Stopped" AND ifnull(`tabPurchase Receipt`.`per_billed`, 0) < 99.99 AND `tabPurchase Receipt`.`company` = "' + doc.company + '" AND `tabPurchase Receipt`.%(key)s LIKE "%s" ORDER BY `tabPurchase Receipt`.`name` DESC LIMIT 50' - } - filter.push(cond); - return{ - filters: filter - } } // Get Print Heading @@ -229,7 +190,6 @@ return{ ['Print Heading', 'docstatus', '!=', 2] ] } - // return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50'; } cur_frm.fields_dict['entries'].grid.get_field("expense_head").get_query = function(doc) { @@ -241,7 +201,6 @@ cur_frm.fields_dict['entries'].grid.get_field("expense_head").get_query = functi 'company': doc.company } } - // return 'SELECT tabAccount.name FROM tabAccount WHERE (tabAccount.debit_or_credit="Debit" OR tabAccount.account_type = "Expense Account") AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'; } cur_frm.cscript.expense_head = function(doc, cdt, cdn){ var d = locals[cdt][cdn]; @@ -256,7 +215,6 @@ cur_frm.cscript.expense_head = function(doc, cdt, cdn){ cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc) { return { - // query: "accounts.utils.get_cost_center_list", filters: { 'company_name': doc.company, 'group_or_ledger': 'Ledger' @@ -307,9 +265,6 @@ cur_frm.fields_dict['entries'].grid.get_field('project_name').get_query = functi ['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/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index ef4b67816c..1487ec9872 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -257,7 +257,6 @@ cur_frm.fields_dict.debit_to.get_query = function(doc) { 'company': doc.company } } - // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } cur_frm.fields_dict.cash_bank_account.get_query = function(doc) { @@ -269,7 +268,6 @@ cur_frm.fields_dict.cash_bank_account.get_query = function(doc) { 'company': doc.company } } - // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } cur_frm.fields_dict.write_off_account.get_query = function(doc) { @@ -281,7 +279,6 @@ cur_frm.fields_dict.write_off_account.get_query = function(doc) { 'company': doc.company } } - // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "Yes" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"' } // Write off cost center @@ -294,7 +291,6 @@ cur_frm.fields_dict.write_off_cost_center.get_query = function(doc) { 'company_name': doc.company } } - // return 'SELECT `tabCost Center`.name FROM `tabCost Center` WHERE `tabCost Center`.group_or_ledger="Ledger" AND `tabCost Center`.docstatus!=2 AND `tabCost Center`.company_name="'+doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s"' } //project name @@ -304,12 +300,6 @@ cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) { query: "controllers.queries.get_project_name", filters: {'customer': doc.customer} } - // 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}); } //Territory @@ -318,7 +308,6 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { 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'; } // Income Account in Details Table @@ -352,14 +341,12 @@ cur_frm.fields_dict['entries'].grid.get_field('warehouse').get_query= function(d ['Bin', 'actual_qty', '>', 0] ] } - // return "SELECT `tabBin`.`warehouse`, `tabBin`.`actual_qty` FROM `tabBin` WHERE `tabBin`.`item_code` = '"+ d.item_code +"' AND ifnull(`tabBin`.`actual_qty`,0) > 0 AND `tabBin`.`warehouse` like '%s' ORDER BY `tabBin`.`warehouse` DESC LIMIT 50"; } // Cost Center in Details Table // ----------------------------- cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc) { return { - // query: "accounts.utils.get_cost_center_list", filters: { 'company_name': doc.company, 'group_or_ledger': 'Ledger' diff --git a/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js b/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js index 81a5c709f0..9ec574ed33 100644 --- a/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js +++ b/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js @@ -144,7 +144,6 @@ cur_frm.fields_dict['other_charges'].grid.get_field("account_head").get_query = ['Account', 'company', '=', doc.company] ] } - // return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.account_type in ("Tax", "Chargeable", "Income Account") AND tabAccount.company = "'+doc.company+'" AND tabAccount.name LIKE "%s"' } cur_frm.fields_dict['other_charges'].grid.get_field("cost_center").get_query = function(doc) { @@ -152,7 +151,6 @@ cur_frm.fields_dict['other_charges'].grid.get_field("cost_center").get_query = f 'company_name': doc.company, 'group_or_ledger': "Ledger" } - // return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `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'; } diff --git a/buying/doctype/purchase_order/purchase_order.js b/buying/doctype/purchase_order/purchase_order.js index 1283ebc434..bccd4a9559 100644 --- a/buying/doctype/purchase_order/purchase_order.js +++ b/buying/doctype/purchase_order/purchase_order.js @@ -113,14 +113,12 @@ cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) { return { filters: {'supplier': doc.supplier} } - // 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'; } cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { return { filters: {'supplier': doc.supplier} } - // 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'; } cur_frm.fields_dict['po_details'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) { @@ -131,18 +129,6 @@ cur_frm.fields_dict['po_details'].grid.get_field('project_name').get_query = fun } } -cur_frm.fields_dict['indent_no'].get_query = function(doc) { - return{ - filters:[ - ['Material Request', 'material_request_type', '=', 'Purchase'], - ['Material Request', 'company', '=', doc.company], - ['Material Request', 'docstatus', '=', '1'], - ['Material Request', 'status', '!=', 'Stopped'], - ['Material Request', 'per_ordered', '<', 99.99] - ] - } -} - cur_frm.cscript.get_last_purchase_rate = function(doc, cdt, cdn){ $c_obj(make_doclist(doc.doctype, doc.name), 'get_last_purchase_rate', '', function(r, rt) { refresh_field(cur_frm.cscript.fname); diff --git a/buying/doctype/quality_inspection/quality_inspection.js b/buying/doctype/quality_inspection/quality_inspection.js index 1c12f3a8a5..72eaecb5a1 100644 --- a/buying/doctype/quality_inspection/quality_inspection.js +++ b/buying/doctype/quality_inspection/quality_inspection.js @@ -48,12 +48,10 @@ cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { filter:{ 'parent': doc.purchase_receipt_no } - // return 'SELECT item_code, item_name, description FROM `tabPurchase Receipt Item` WHERE parent = "'+ doc.purchase_receipt_no +'" and docstatus != 2 AND item_code LIKE "%s" ORDER BY item_code ASC LIMIT 50'; else if (doc.delivery_note_no) filter:{ 'parent': doc.delivery_note_no } - // return 'SELECT item_code, item_name, description FROM `tabDelivery Note Item` WHERE parent = "'+ doc.delivery_note_no +'" and docstatus != 2 AND item_code LIKE "%s" ORDER BY item_code ASC LIMIT 50'; return{ filters: filter } diff --git a/buying/doctype/supplier_quotation/supplier_quotation.js b/buying/doctype/supplier_quotation/supplier_quotation.js index d0f1948ef0..54ef722885 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/buying/doctype/supplier_quotation/supplier_quotation.js @@ -72,18 +72,6 @@ cur_frm.fields_dict['quotation_items'].grid.get_field('project_name').get_query } } -cur_frm.fields_dict['indent_no'].get_query = function(doc) { - return{ - filters:[ - ['Material Request', 'material_request_type', '=', 'Purchase'], - ['Material Request', 'company', '=', doc.company], - ['Material Request', 'docstatus', '=', 1], - ['Material Request', 'status', '!=', 'Stopped'], - ['Material Request', 'per_ordered', '<', 99.99] - ] - } -} - cur_frm.cscript.supplier_address = function(doc, dt, dn) { if (doc.supplier) { get_server_fields("get_supplier_address", JSON.stringify({supplier: doc.supplier, @@ -102,4 +90,4 @@ cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { return { filters:{'supplier': doc.supplier} } -} +} \ No newline at end of file diff --git a/hr/doctype/appraisal/appraisal.js b/hr/doctype/appraisal/appraisal.js index ac2b1234d2..2289064baa 100644 --- a/hr/doctype/appraisal/appraisal.js +++ b/hr/doctype/appraisal/appraisal.js @@ -84,7 +84,5 @@ cur_frm.cscript.calculate_total = function(doc,cdt,cdn){ } cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { - return{ - query:"controllers.queries.employee_query" - } + 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 065bb47711..60c159dd46 100644 --- a/hr/doctype/salary_structure/salary_structure.js +++ b/hr/doctype/salary_structure/salary_structure.js @@ -73,7 +73,5 @@ cur_frm.cscript.validate = function(doc, cdt, cdn) { } cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { - return{ - query:"controllers.queries.employee_query" - } + 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 e3518591b3..7dc905a536 100644 --- a/manufacturing/doctype/production_order/production_order.js +++ b/manufacturing/doctype/production_order/production_order.js @@ -106,16 +106,12 @@ cur_frm.fields_dict['production_item'].get_query = function(doc) { ['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{ 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/projects/doctype/task/task.js b/projects/doctype/task/task.js index 097119ffb6..cb2c539d63 100644 --- a/projects/doctype/task/task.js +++ b/projects/doctype/task/task.js @@ -22,7 +22,7 @@ erpnext.projects.Task = wn.ui.form.Controller.extend({ setup: function() { this.frm.fields_dict.project.get_query = function() { return { - query: "projects.doctype.tast.task.get_project" + query: "projects.doctype.task.task.get_project" } }; }, diff --git a/projects/doctype/task/task.py b/projects/doctype/task/task.py index 1dfcdc1af1..0072b1f70d 100644 --- a/projects/doctype/task/task.py +++ b/projects/doctype/task/task.py @@ -96,7 +96,7 @@ def get_events(start, end, filters=None): 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 + 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), diff --git a/selling/doctype/customer/customer.js b/selling/doctype/customer/customer.js index f92a2a90e6..cd530a25ba 100644 --- a/selling/doctype/customer/customer.js +++ b/selling/doctype/customer/customer.js @@ -125,7 +125,6 @@ cur_frm.fields_dict['customer_group'].get_query = function(doc,dt,dn) { 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'; } diff --git a/selling/doctype/installation_note/installation_note.js b/selling/doctype/installation_note/installation_note.js index 8574da3123..4cbd67d729 100644 --- a/selling/doctype/installation_note/installation_note.js +++ b/selling/doctype/installation_note/installation_note.js @@ -62,27 +62,20 @@ 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 filter = { - 'company': doc.company, - 'docstatus': 1, - 'per_installed': 99.99 + 'company': doc.company, + 'docstatus': 1, + 'per_installed': 99.99 }; if(doc.customer) filter['customer'] = doc.customer; - return{ - filters:filter - } - // { - // 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}); + return { filters: filter } } - cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { return{ - filters{ 'is_group': "No" } + 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) { @@ -93,14 +86,12 @@ cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { 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{ 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 = function(doc,cdt,cdn) { diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index f88402d882..b87fee196d 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -157,18 +157,12 @@ cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { 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 { 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'; } } @@ -177,7 +171,6 @@ cur_frm.fields_dict['lead'].get_query = function(doc,cdt,cdn){ 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) { @@ -243,7 +236,6 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { 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 = function(doc,cdt,cdn) { return { query:"controllers.queries.lead_query" } } diff --git a/selling/doctype/quotation/quotation.js b/selling/doctype/quotation/quotation.js index ccb4998eaf..cfaf61172a 100644 --- a/selling/doctype/quotation/quotation.js +++ b/selling/doctype/quotation/quotation.js @@ -202,7 +202,6 @@ cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query= 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/sales_bom/sales_bom.js b/selling/doctype/sales_bom/sales_bom.js index f60b6e3122..7d79340678 100644 --- a/selling/doctype/sales_bom/sales_bom.js +++ b/selling/doctype/sales_bom/sales_bom.js @@ -27,9 +27,6 @@ cur_frm.fields_dict.new_item_code.get_query = function() { 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/setup/doctype/authorization_rule/authorization_rule.js b/setup/doctype/authorization_rule/authorization_rule.js index 76a87080c3..1866cbcc5d 100644 --- a/setup/doctype/authorization_rule/authorization_rule.js +++ b/setup/doctype/authorization_rule/authorization_rule.js @@ -97,8 +97,6 @@ cur_frm.fields_dict['system_role'].get_query = function(doc) { ['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 @@ -117,19 +115,16 @@ cur_frm.fields_dict['master_name'].get_query = function(doc){ ['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 { 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 { 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 = function(doc,cdt,cdn) { diff --git a/setup/doctype/company/company.js b/setup/doctype/company/company.js index 60a32ae10a..dfe8e2ae87 100644 --- a/setup/doctype/company/company.js +++ b/setup/doctype/company/company.js @@ -55,13 +55,8 @@ cur_frm.fields_dict.default_bank_account.get_query = function(doc) { '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.payables_group.get_query = cur_frm.fields_dict.receivables_group.get_query; cur_frm.fields_dict.receivables_group.get_query = function(doc) { @@ -71,17 +66,11 @@ cur_frm.fields_dict.receivables_group.get_query = function(doc) { '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'; -// } - 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", "filters": { "is_pl_account": "No", "debit_or_credit": "Debit", @@ -93,7 +82,6 @@ if (sys_defaults.auto_inventory_accounting) { cur_frm.fields_dict["stock_adjustment_account"].get_query = function(doc) { return { - // "query": "accounts.utils.get_account_list", "filters": { "is_pl_account": "Yes", "debit_or_credit": "Debit", @@ -108,7 +96,6 @@ 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", "filters": { "is_pl_account": "No", "debit_or_credit": "Credit", @@ -120,7 +107,6 @@ if (sys_defaults.auto_inventory_accounting) { cur_frm.fields_dict["stock_adjustment_cost_center"].get_query = function(doc) { return { - // "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 9d4d8bf94c..db0ed91bfd 100755 --- a/setup/doctype/contact_control/contact_control.js +++ b/setup/doctype/contact_control/contact_control.js @@ -26,10 +26,9 @@ if(cur_frm.fields_dict['territory']){ cur_frm.fields_dict['territory'].get_query = function(doc,dt,dn) { return { filters: { - 'is_group' = "No" + '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 18931eb071..e865860a24 100644 --- a/setup/doctype/customer_group/customer_group.js +++ b/setup/doctype/customer_group/customer_group.js @@ -36,8 +36,4 @@ cur_frm.fields_dict['parent_customer_group'].get_query = function(doc,cdt,cdn) { '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 581039370b..b642735215 100644 --- a/setup/doctype/item_group/item_group.js +++ b/setup/doctype/item_group/item_group.js @@ -40,5 +40,4 @@ cur_frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) { ['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 5db60c5951..acf6b312bd 100644 --- a/setup/doctype/sales_partner/sales_partner.js +++ b/setup/doctype/sales_partner/sales_partner.js @@ -100,5 +100,4 @@ cur_frm.fields_dict['partner_target_details'].grid.get_field("item_group").get_q 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 e0d06395e0..fd03a441ee 100644 --- a/setup/doctype/sales_person/sales_person.js +++ b/setup/doctype/sales_person/sales_person.js @@ -41,14 +41,12 @@ cur_frm.fields_dict['parent_sales_person'].get_query = function(doc,cdt,cdn) { ['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{ 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 = function(doc,cdt,cdn) { diff --git a/setup/doctype/territory/territory.js b/setup/doctype/territory/territory.js index 3164ba279d..7fdfee54d6 100644 --- a/setup/doctype/territory/territory.js +++ b/setup/doctype/territory/territory.js @@ -36,7 +36,6 @@ cur_frm.fields_dict['parent_territory'].get_query = function(doc,cdt,cdn) { ['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'; } @@ -45,5 +44,4 @@ cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = f 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/item/item.js b/stock/doctype/item/item.js index a0937fb285..3d427ad311 100644 --- a/stock/doctype/item/item.js +++ b/stock/doctype/item/item.js @@ -57,7 +57,6 @@ cur_frm.fields_dict['default_bom'].get_query = function(doc) { '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' } diff --git a/stock/doctype/landed_cost_wizard/landed_cost_wizard.js b/stock/doctype/landed_cost_wizard/landed_cost_wizard.js index 86787cac65..a093d6f264 100644 --- a/stock/doctype/landed_cost_wizard/landed_cost_wizard.js +++ b/stock/doctype/landed_cost_wizard/landed_cost_wizard.js @@ -28,5 +28,4 @@ return{ ['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 b658220a1c..e19ab49300 100644 --- a/stock/doctype/packing_slip/packing_slip.js +++ b/stock/doctype/packing_slip/packing_slip.js @@ -18,7 +18,6 @@ cur_frm.fields_dict['delivery_note'].get_query = function(doc, cdt, cdn) { return{ filters:{ 'docstatus': 0} } - // return 'SELECT name FROM `tabDelivery Note` WHERE docstatus=0 AND %(key)s LIKE "%s"'; } diff --git a/stock/doctype/serial_no/serial_no.js b/stock/doctype/serial_no/serial_no.js index df7058a951..0253ffbe83 100644 --- a/stock/doctype/serial_no/serial_no.js +++ b/stock/doctype/serial_no/serial_no.js @@ -49,7 +49,6 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { 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 diff --git a/support/doctype/customer_issue/customer_issue.js b/support/doctype/customer_issue/customer_issue.js index 1f68602684..cd744ec121 100644 --- a/support/doctype/customer_issue/customer_issue.js +++ b/support/doctype/customer_issue/customer_issue.js @@ -68,17 +68,12 @@ cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { 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{ 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) { @@ -110,10 +105,6 @@ cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { 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{ @@ -121,9 +112,6 @@ cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { ['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'; } } @@ -134,10 +122,6 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { 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 = function(doc,cdt,cdn) { From f52dc07a5875e0cea89744610a132e9b93007aa9 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 10 Jul 2013 13:07:49 +0530 Subject: [PATCH 6/9] queries to server side --- .../mode_of_payment/mode_of_payment.js | 11 ++-- .../doctype/sales_invoice/sales_invoice.js | 8 ++- .../doctype/sales_invoice/sales_invoice.py | 11 ++++ .../purchase_common/purchase_common.js | 28 ++++++--- controllers/queries.py | 17 ++++-- .../bom_replace_tool/bom_replace_tool.js | 10 ++- .../production_order/production_order.js | 5 +- projects/doctype/time_log/time_log.js | 6 +- selling/doctype/sales_common/sales_common.js | 61 +++++++++++-------- selling/doctype/sales_common/sales_common.py | 22 +++++++ 10 files changed, 125 insertions(+), 54 deletions(-) diff --git a/accounts/doctype/mode_of_payment/mode_of_payment.js b/accounts/doctype/mode_of_payment/mode_of_payment.js index 85b2ab1696..e3625e6100 100644 --- a/accounts/doctype/mode_of_payment/mode_of_payment.js +++ b/accounts/doctype/mode_of_payment/mode_of_payment.js @@ -15,8 +15,11 @@ // along with this program. If not, see . cur_frm.set_query("default_account", function(doc) { - return erpnext.queries.account({ - account_type: "Bank or Cash", - company: doc.company - }); + return{ + query: "controllers.queries.account_query", + filters: { + 'account_type': "Bank or Cash", + 'company': doc.company + } + } }); \ No newline at end of file diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index 1487ec9872..421630b450 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -313,14 +313,16 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { // Income Account in Details Table // -------------------------------- cur_frm.set_query("income_account", "entries", function(doc) { - return 'SELECT tabAccount.name FROM tabAccount WHERE (tabAccount.debit_or_credit="Credit" OR tabAccount.account_type = "Income Account") AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'; -}) + return{ + query: "accounts.doctype.sales_invoice.sales_invoice.get_income_account", + filters: {'company': doc.company} + } +}); // expense account if (sys_defaults.auto_inventory_accounting) { cur_frm.fields_dict['entries'].grid.get_field('expense_account').get_query = function(doc) { return { - // "query": "accounts.utils.get_account_list", filters: { 'is_pl_account': 'Yes', 'debit_or_credit': 'Debit', diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index e0147b12d3..d7ab91a5ca 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -984,3 +984,14 @@ def get_bank_cash_account(mode_of_payment): return { "cash_bank_account": val } + +def get_income_account(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + + return webnotes.conn.sql("""select tabAccount.name from `tabAccount` + where (tabAccount.debit_or_credit="Credit" + or tabAccount.account_type = "Income Account") + and tabAccount.group_or_ledger="Ledger" and tabAccount.docstatus!=2 + and tabAccount.company = '%(company)s' and tabAccount.%(key)s LIKE '%(txt)s' + %(mcond)s""" % {'company': filters['company'], 'key': searchfield, + 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield)}) \ No newline at end of file diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index 1b7dcf0e47..7d3d600c0a 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -28,27 +28,37 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ if(this.frm.fields_dict.price_list_name) { this.frm.set_query("price_list_name", function() { - return repl("select name, currency from `tabPrice List` \ - where buying_or_selling = 'Buying' and name like \"%s%%\""); + return{ + filters: { 'buying_or_selling': "Buying" } + } }); this.frm.set_query("price_list_currency", function() { - return repl("select distinct ref_currency from `tabItem Price` \ - where price_list_name=\"%(price_list_name)s\" and buying_or_selling = 'Buying' \ - and ref_currency like \"%s%%\"", - {price_list_name: me.frm.doc.price_list_name}); + return{ + filters: { + 'price_list_name': me.frm.doc.price_list_name, + 'buying_or_selling': "Buying" + } + } }); } if(this.frm.fields_dict.supplier) { - this.frm.set_query("supplier", erpnext.utils.supplier_query); + this.frm.set_query("supplier", function() { + return{ query:"controllers.queries.supplier_query" }}); } this.frm.set_query("item_code", this.frm.cscript.fname, function() { if(me.frm.doc.is_subcontracted == "Yes") { - return erpnext.queries.item({'ifnull(tabItem.is_sub_contracted_item, "No")': "Yes"}); + return{ + query:"controllers.queries.item_query", + filters:{ 'is_sub_contracted_item': 'Yes' } + } } else { - return erpnext.queries.item({'ifnull(tabItem.is_purchase_item, "No")': "Yes"}); + return{ + query:"controllers.queries.item_query", + filters:{ 'is_purchase_item': 'Yes' } + } } }); }, diff --git a/controllers/queries.py b/controllers/queries.py index ac8ab25122..67d53184d5 100644 --- a/controllers/queries.py +++ b/controllers/queries.py @@ -20,7 +20,13 @@ import webnotes def get_filters_cond(doctype, filters, conditions): if filters: if isinstance(filters, dict): - filters = map(lambda f: [doctype, f[0], "=", f[1]], filters.items()) + filters = filters.items() + flt = [] + for f in filters: + if f[1][0] == '!': + flt.append([doctype, f[0], '!=', f[1][1:]]) + else: + flt.append([doctype, f[0], '=', f[1]]) from webnotes.widgets.reportview import build_filter_conditions build_filter_conditions(filters, conditions) @@ -36,6 +42,7 @@ def get_match_cond(doctype, searchfield = 'name'): from webnotes.widgets.reportview import build_match_conditions cond = build_match_conditions(doctype, fields) + if cond: cond = ' and ' + cond else: @@ -81,10 +88,12 @@ def lead_query(doctype, txt, searchfield, start, page_len, filters): # searches for customer def customer_query(doctype, txt, searchfield, start, page_len, filters): cust_master_name = webnotes.defaults.get_user_default("cust_master_name") + if cust_master_name == "Customer Name": fields = ["name", "customer_group", "territory"] else: fields = ["name", "customer_name", "customer_group", "territory"] + fields = ", ".join(fields) return webnotes.conn.sql("""select %(field)s from `tabCustomer` where docstatus < 2 and @@ -142,6 +151,7 @@ def account_query(doctype, txt, searchfield, start, page_len, filters): def item_query(doctype, txt, searchfield, start, page_len, filters): conditions = [] + return webnotes.conn.sql("""select tabItem.name, if(length(tabItem.item_name) > 40, concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name, @@ -158,6 +168,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters): def bom(doctype, txt, searchfield, start, page_len, filters): conditions = [] + return webnotes.conn.sql("""select tabBOM.name, tabBOM.item from tabBOM where tabBOM.docstatus=1 and tabBOM.is_active=1 @@ -166,10 +177,6 @@ def bom(doctype, txt, searchfield, start, page_len, filters): 'fcond': get_filters_cond(doctype, filters, conditions), 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) -# erpnext.queries.task = function() { -# return { query: "projects.utils.query_task" }; -# }; - def get_project_name(doctype, txt, searchfield, start, page_len, filters): cond = '' if filters['customer']: diff --git a/manufacturing/doctype/bom_replace_tool/bom_replace_tool.js b/manufacturing/doctype/bom_replace_tool/bom_replace_tool.js index c98603cfb9..bad03ac2ae 100644 --- a/manufacturing/doctype/bom_replace_tool/bom_replace_tool.js +++ b/manufacturing/doctype/bom_replace_tool/bom_replace_tool.js @@ -20,10 +20,16 @@ cur_frm.cscript.refresh = function(doc) { } cur_frm.set_query("current_bom", function(doc) { - return erpnext.queries.bom({name: "!" + doc.new_bom}); + return{ + query:"controllers.queries.bom", + filters: {name: "!" + doc.new_bom} + } }); cur_frm.set_query("new_bom", function(doc) { - return erpnext.queries.bom({name: "!" + doc.current_bom}); + return{ + query:"controllers.queries.bom", + filters: {name: "!" + doc.current_bom} + } }); \ 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 7dc905a536..c3a45e2f4a 100644 --- a/manufacturing/doctype/production_order/production_order.js +++ b/manufacturing/doctype/production_order/production_order.js @@ -117,6 +117,9 @@ cur_frm.fields_dict['project_name'].get_query = function(doc, dt, dn) { cur_frm.set_query("bom_no", function(doc) { if (doc.production_item) { - return erpnext.queries.bom({item: cstr(doc.production_item)}); + return{ + query:"controllers.queries.bom", + filters: {item: cstr(doc.production_item)} + } } else msgprint(" Please enter Production Item first"); }); \ No newline at end of file diff --git a/projects/doctype/time_log/time_log.js b/projects/doctype/time_log/time_log.js index 22f9610b8f..69ec3043c9 100644 --- a/projects/doctype/time_log/time_log.js +++ b/projects/doctype/time_log/time_log.js @@ -2,8 +2,8 @@ wn.provide("erpnext.projects"); erpnext.projects.TimeLog = wn.ui.form.Controller.extend({ setup: function() { - this.frm.set_query("task", erpnext.queries.task); - } -}); + this.frm.set_query("task", function() { + return { query: "projects.utils.query_task" } + }); cur_frm.cscript = new erpnext.projects.TimeLog({frm: cur_frm}); \ 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 02db55a29d..8d869501f2 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -36,33 +36,34 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ } this.frm.set_query("customer_address", function() { - return 'SELECT name, address_line1, city FROM tabAddress \ - WHERE customer = "'+ me.frm.doc.customer +'" AND docstatus != 2 AND \ - %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; + return { + filters: {'customer': me.frm.doc.customer } + } }); this.frm.set_query("contact_person", function() { - return 'SELECT name, CONCAT(first_name," ",ifnull(last_name,"")) As FullName, \ - department, designation FROM tabContact WHERE customer = "'+ me.frm.doc.customer + - '" AND docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; + return { + filters: {'customer': me.frm.doc.customer } + } }); if(this.frm.fields_dict.charge) { this.frm.set_query("charge", function() { - return 'SELECT DISTINCT `tabSales Taxes and Charges Master`.name FROM \ - `tabSales Taxes and Charges Master` \ - WHERE `tabSales Taxes and Charges Master`.company = "' + me.frm.doc.company + - '" AND `tabSales Taxes and Charges Master`.company is not NULL \ - AND `tabSales Taxes and Charges Master`.docstatus != 2 \ - AND `tabSales Taxes and Charges Master`.%(key)s LIKE "%s" \ - ORDER BY `tabSales Taxes and Charges Master`.name LIMIT 50'; + return { + filters: [ + ['Sales Taxes and Charges Master', 'company', '=', me.frm.doc.company], + ['Sales Taxes and Charges Master', 'company', 'is not', 'NULL'], + ['Sales Taxes and Charges Master', 'docstatus', '!=', 2] + ] + } }); } 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); + this.frm.fields_dict.lead && this.frm.set_query("lead", function(doc,cdt,cdn) { + return{ query:"controllers.queries.lead_query" } }); if(!this.fname) { return; @@ -71,8 +72,10 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ if(this.frm.fields_dict[this.fname].grid.get_field('item_code')) { this.frm.set_query("item_code", this.fname, function() { return me.frm.doc.order_type === "Maintenance" ? - erpnext.queries.item({'ifnull(tabItem.is_service_item, "No")': "Yes"}) : - erpnext.queries.item({'ifnull(tabItem.is_sales_item, "No")': "Yes"}); + { query:"controllers.queries.item_query", + filters:{'is_service_item': 'Yes'}} : + { query:"controllers.queries.item_query", + filters:{'is_sales_item': 'Yes' }} ; }); } @@ -83,18 +86,22 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ wn.throw("Please enter Item Code to get batch no"); } else { if(item.warehouse) { - return "select batch_no from `tabStock Ledger Entry` sle \ - where item_code = '" + item.item_code + - "' and warehouse = '" + item.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 >= '" + me.frm.doc.posting_date + - "' and docstatus != 2) group by batch_no having sum(actual_qty) > 0 \ - order by batch_no desc limit 50"; + return { + query : "selling.doctype.sales_common.sales_common.get_batch_no", + filters: { + 'item_code': item.item_code, + 'warehouse': item.warehouse, + 'posting_date': me.frm.doc.posting_date + } + } } else { - return "SELECT name FROM tabBatch WHERE docstatus != 2 AND item = '" + - item.item_code + "' and expiry_date >= '" + me.frm.doc.posting_date + - "' AND name like '%s' ORDER BY name DESC LIMIT 50"; + return{ + query : "selling.doctype.sales_common.sales_common.get_batch_no", + filters: { + 'item': item.item_code, + 'posting_date': me.frm.doc.posting_date + } + } } } }); diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index f34ebf917d..dfbfb48958 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -365,3 +365,25 @@ class DocType(TransactionBase): dt = webnotes.conn.sql("select transaction_date from `tab%s` where name = '%s'" % (d.prevdoc_doctype, d.prevdoc_docname)) d.prevdoc_date = (dt and dt[0][0]) and dt[0][0].strftime('%Y-%m-%d') or '' +def get_batch_no(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + + if filters.has_key('warehouse'): + return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle + where item_code = '%(item_code)s' and warehouse = '%(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'], 'warehouse': filters['warehouse'], + 'posting_date': filters['posting_date'], 'txt': 'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield),'start': start, 'page_len': page_len}) + else: + return webnotes.conn.sql("""select name from tabBatch where docstatus != 2 + and item = '%(item_code)s' and expiry_date >= '%(posting_date)s' + and name like '%(txt)s' %(mcond)s ORDER BY name DESC LIMIT 50""" % + {'item_code': filters['item_code'], 'posting_date': filters['posting_date'], + 'txt': 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), + 'start': start, 'page_len': page_len}) \ No newline at end of file From 2deca5f3f676c944c354ed039e68756d28d9d27c Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 10 Jul 2013 14:31:29 +0530 Subject: [PATCH 7/9] queries to server side --- buying/doctype/purchase_common/purchase_common.js | 4 ++-- controllers/queries.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index 7d3d600c0a..9b05bc5e34 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -56,8 +56,8 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ } } else { return{ - query:"controllers.queries.item_query", - filters:{ 'is_purchase_item': 'Yes' } + query: "controllers.queries.item_query", + filters: { 'is_purchase_item': 'Yes' } } } }); diff --git a/controllers/queries.py b/controllers/queries.py index 67d53184d5..b3556e5229 100644 --- a/controllers/queries.py +++ b/controllers/queries.py @@ -29,7 +29,7 @@ def get_filters_cond(doctype, filters, conditions): flt.append([doctype, f[0], '=', f[1]]) from webnotes.widgets.reportview import build_filter_conditions - build_filter_conditions(filters, conditions) + build_filter_conditions(flt, conditions) cond = ' and ' + ' and '.join(conditions) else: cond = '' From a29b69245ea1cbbc998704d71edbf2b3204d8465 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 10 Jul 2013 16:06:31 +0530 Subject: [PATCH 8/9] get_query to servet side --- .../payment_to_invoice_matching_tool.py | 38 ++++--- controllers/queries.py | 104 ++++++++++++------ 2 files changed, 93 insertions(+), 49 deletions(-) diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py index 633bdd1590..b1bec06bad 100644 --- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py +++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py @@ -141,17 +141,27 @@ class DocType: msgprint("No amount allocated.", raise_exception=1) def gl_entry_details(doctype, txt, searchfield, start, page_len, filters): - ("""select gle.voucher_no, gle.posting_date, gle.%(account_type)s - from `tabGL Entry` gle - where gle.account = '%(acc)s' and gle.voucher_type = '%(dt)s' - and gle.voucher_no like '%s' and ifnull(gle.is_cancelled, 'No') = 'No' - and (ifnull(gle.against_voucher, '') = '' or ifnull(gle.against_voucher, '') = gle.voucher_no ) - and ifnull(gle.%(account_type)s, 0) > 0 - and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0) - from `tabGL Entry` - where against_voucher_type = '%(dt)s' and against_voucher = gle.voucher_no - and voucher_no != gle.voucher_no - and ifnull(is_cancelled, 'No') = 'No') != abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)) - ORDER BY gle.posting_date DESC, gle.voucher_no DESC limit %(start)s, %(page_len)s"""% - {dt:filters["dt"], acc:filters["acc"], account_type: filters['account_type'], "start": start, - "page_len": page_len}) \ No newline at end of file + from controllers.queries import get_match_cond + + return webnotes.conn.sql("""select gle.voucher_no, gle.posting_date, + gle.%(account_type)s from `tabGL Entry` gle + where gle.account = '%(acc)s' + and gle.voucher_type = '%(dt)s' + and gle.voucher_no like '%(txt)s' + and ifnull(gle.is_cancelled, 'No') = 'No' + and (ifnull(gle.against_voucher, '') = '' + or ifnull(gle.against_voucher, '') = gle.voucher_no ) + and ifnull(gle.%(account_type)s, 0) > 0 + and (select ifnull(abs(sum(ifnull(debit, 0)) + - sum(ifnull(credit, 0))), 0) + from `tabGL Entry` + where against_voucher_type = '%(dt)s' + and against_voucher = gle.voucher_no + and voucher_no != gle.voucher_no + and ifnull(is_cancelled, 'No') = 'No') + != abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)) + %(mcond)s + ORDER BY gle.posting_date desc, gle.voucher_no desc + limit %(start)s, %(page_len)s""" % {dt:filters["dt"], acc:filters["acc"], + account_type: filters['account_type'], 'mcond':get_match_cond(doctype, searchfield) + 'txt': "%%%s%%" % txt,"start": start, "page_len": page_len}) \ No newline at end of file diff --git a/controllers/queries.py b/controllers/queries.py index b3556e5229..e397420e3e 100644 --- a/controllers/queries.py +++ b/controllers/queries.py @@ -16,6 +16,7 @@ from __future__ import unicode_literals import webnotes +from webnotes.utils import cstr def get_filters_cond(doctype, filters, conditions): if filters: @@ -52,37 +53,51 @@ def get_match_cond(doctype, searchfield = 'name'): # searches for enabled profiles def profile_query(doctype, txt, searchfield, start, page_len, filters): return webnotes.conn.sql("""select name, concat_ws(' ', first_name, middle_name, last_name) - from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and - name not in ('Administrator', 'Guest') and (%(key)s like "%(txt)s" or - concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s") %(mcond)s + from `tabProfile` + where ifnull(enabled, 0)=1 + and docstatus < 2 + and name not in ('Administrator', 'Guest') + and (%(key)s like "%(txt)s" + or concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s") + %(mcond)s order by case when name like "%(txt)s" then 0 else 1 end, case when concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s" then 0 else 1 end, - name asc limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt, + 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}) # searches for active employees def employee_query(doctype, txt, searchfield, start, page_len, filters): return webnotes.conn.sql("""select name, employee_name from `tabEmployee` - where status = 'Active' and docstatus < 2 and - (%(key)s like "%(txt)s" or employee_name like "%(txt)s") %(mcond)s + where status = 'Active' + and docstatus < 2 + and (%(key)s like "%(txt)s" + or employee_name like "%(txt)s") + %(mcond)s order by case when name like "%(txt)s" then 0 else 1 end, case when employee_name like "%(txt)s" then 0 else 1 end, - name limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt, + name + limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) # searches for leads which are not converted def lead_query(doctype, txt, searchfield, start, page_len, filters): return webnotes.conn.sql("""select name, lead_name, company_name from `tabLead` - where docstatus < 2 and ifnull(status, '') != 'Converted' and - (%(key)s like "%(txt)s" or lead_name like "%(txt)s" or company_name like "%(txt)s") %(mcond)s + where docstatus < 2 + and ifnull(status, '') != 'Converted' + and (%(key)s like "%(txt)s" + or lead_name like "%(txt)s" + or company_name like "%(txt)s") + %(mcond)s order by case when name like "%(txt)s" then 0 else 1 end, case when lead_name like "%(txt)s" then 0 else 1 end, case when company_name like "%(txt)s" then 0 else 1 end, - lead_name asc limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt, + lead_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}) # searches for customer @@ -96,12 +111,16 @@ def customer_query(doctype, txt, searchfield, start, page_len, filters): fields = ", ".join(fields) - return webnotes.conn.sql("""select %(field)s from `tabCustomer` where docstatus < 2 and - (%(key)s like "%(txt)s" or customer_name like "%(txt)s") %(mcond)s + return webnotes.conn.sql("""select %(field)s from `tabCustomer` + where docstatus < 2 + and (%(key)s like "%(txt)s" + or customer_name like "%(txt)s") + %(mcond)s order by case when name like "%(txt)s" then 0 else 1 end, case when customer_name like "%(txt)s" then 0 else 1 end, - name, customer_name limit %(start)s, %(page_len)s""" % {'field': fields,'key': searchfield, + name, customer_name + limit %(start)s, %(page_len)s""" % {'field': fields,'key': searchfield, 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) @@ -114,12 +133,16 @@ def supplier_query(doctype, txt, searchfield, start, page_len, filters): fields = ["name", "supplier_name", "supplier_type"] fields = ", ".join(fields) - return webnotes.conn.sql("""select %(field)s from `tabSupplier` where docstatus < 2 and \ - (%(key)s like "%(txt)s" or supplier_name like "%(txt)s") %(mcond)s + return webnotes.conn.sql("""select %(field)s from `tabSupplier` + where docstatus < 2 + and (%(key)s like "%(txt)s" + or supplier_name like "%(txt)s") + %(mcond)s order by case when name like "%(txt)s" then 0 else 1 end, case when supplier_name like "%(txt)s" then 0 else 1 end, - name, supplier_name limit %(start)s, %(page_len)s """ % {'field': fields,'key': searchfield, + name, supplier_name + limit %(start)s, %(page_len)s """ % {'field': fields,'key': searchfield, 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) @@ -131,9 +154,11 @@ def item_std(doctype, txt, searchfield, start, page_len, filters): concat(substr(tabItem.description, 1, 40), "..."), description) as decription FROM tabItem WHERE tabItem.docstatus!=2 - AND tabItem.%(key)s LIKE "%(txt)s" %(mcond)s limit %(start)s, %(page_len)s """ % - {'key': searchfield, 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), - 'start': start, 'page_len': page_len}) + and tabItem.%(key)s LIKE "%(txt)s" + %(mcond)s + limit %(start)s, %(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield), 'start': start, + 'page_len': page_len}) def account_query(doctype, txt, searchfield, start, page_len, filters): conditions = [] @@ -144,8 +169,10 @@ def account_query(doctype, txt, searchfield, start, page_len, filters): return webnotes.conn.sql("""select tabAccount.name, tabAccount.parent_account, tabAccount.debit_or_credit from tabAccount - where tabAccount.docstatus!=2 and tabAccount.%(key)s LIKE "%(txt)s" - %(fcond)s %(mcond)s limit %(start)s, %(page_len)s""" % {'key': searchfield, + where tabAccount.docstatus!=2 + and tabAccount.%(key)s LIKE "%(txt)s" + %(fcond)s %(mcond)s + limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt, 'fcond': get_filters_cond(doctype, filters, conditions), 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) @@ -157,12 +184,14 @@ def item_query(doctype, txt, searchfield, start, page_len, filters): concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name, if(length(tabItem.description) > 40, \ concat(substr(tabItem.description, 1, 40), "..."), description) as decription - FROM tabItem - WHERE tabItem.docstatus!=2 - AND (ifnull(`tabItem`.`end_of_life`,"") in ("", "0000-00-00") - OR `tabItem`.`end_of_life` > NOW()) - AND (tabItem.%(key)s LIKE "%(txt)s" OR tabItem.item_name LIKE "%(txt)s") %(fcond)s - %(mcond)s limit %(start)s,%(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt, + from tabItem + where tabItem.docstatus!=2 + and (ifnull(`tabItem`.`end_of_life`,"") in ("", "0000-00-00") + or `tabItem`.`end_of_life` > NOW()) + and (tabItem.%(key)s LIKE "%(txt)s" + or tabItem.item_name LIKE "%(txt)s") + %(fcond)s %(mcond)s + limit %(start)s,%(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt, 'fcond': get_filters_cond(doctype, filters, conditions), 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) @@ -171,17 +200,22 @@ def bom(doctype, txt, searchfield, start, page_len, filters): return webnotes.conn.sql("""select tabBOM.name, tabBOM.item from tabBOM - where tabBOM.docstatus=1 and tabBOM.is_active=1 - and tabBOM.%(key)s like "%s" %(fcond)s %(mcond)s limit %(start)s, - %(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt, - 'fcond': get_filters_cond(doctype, filters, conditions), 'mcond':get_match_cond(doctype, searchfield), - 'start': start, 'page_len': page_len}) + where tabBOM.docstatus=1 + and tabBOM.is_active=1 + and tabBOM.%(key)s like "%s" + %(fcond)s %(mcond)s + limit %(start)s, %(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % txt, + 'fcond': get_filters_cond(doctype, filters, conditions), + 'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) def get_project_name(doctype, txt, searchfield, start, page_len, filters): cond = '' if filters['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 - `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 + 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 From ee85cfd476e1c1423552f77b5645fe51f0a5c41d Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 10 Jul 2013 17:35:14 +0530 Subject: [PATCH 9/9] get_query to server side --- .../payment_to_invoice_matching_tool.py | 5 ++- accounts/doctype/pos_setting/pos_setting.js | 2 +- .../doctype/sales_invoice/sales_invoice.py | 10 +++-- .../quality_inspection/quality_inspection.js | 23 +++++------ .../supplier_quotation/supplier_quotation.js | 2 +- projects/doctype/task/task.py | 11 ++--- selling/doctype/opportunity/opportunity.py | 11 ++--- selling/doctype/quotation/quotation.js | 2 +- selling/doctype/quotation/quotation.py | 35 ++++++++++------ selling/doctype/sales_common/sales_common.py | 40 ++++++++++++------- stock/doctype/packing_slip/packing_slip.py | 6 ++- stock/doctype/stock_entry/stock_entry.py | 30 +++++++++----- .../maintenance_schedule.py | 22 +++++----- 13 files changed, 116 insertions(+), 83 deletions(-) diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py index b1bec06bad..07a97d8823 100644 --- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py +++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py @@ -153,13 +153,14 @@ def gl_entry_details(doctype, txt, searchfield, start, page_len, filters): or ifnull(gle.against_voucher, '') = gle.voucher_no ) and ifnull(gle.%(account_type)s, 0) > 0 and (select ifnull(abs(sum(ifnull(debit, 0)) - - sum(ifnull(credit, 0))), 0) + - sum(ifnull(credit, 0))), 0) from `tabGL Entry` where against_voucher_type = '%(dt)s' and against_voucher = gle.voucher_no and voucher_no != gle.voucher_no and ifnull(is_cancelled, 'No') = 'No') - != abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)) + != abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0) + ) %(mcond)s ORDER BY gle.posting_date desc, gle.voucher_no desc limit %(start)s, %(page_len)s""" % {dt:filters["dt"], acc:filters["acc"], diff --git a/accounts/doctype/pos_setting/pos_setting.js b/accounts/doctype/pos_setting/pos_setting.js index aa9cf11539..991c8daadf 100755 --- a/accounts/doctype/pos_setting/pos_setting.js +++ b/accounts/doctype/pos_setting/pos_setting.js @@ -55,7 +55,7 @@ cur_frm.fields_dict['cost_center'].get_query = function(doc,cdt,cdn) { return{ filters:{ 'company_name': doc.company, - 'group_or_ledger': "Ledger", + 'group_or_ledger': "Ledger" } } } diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index d7ab91a5ca..e42cb73340 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -990,8 +990,10 @@ def get_income_account(doctype, txt, searchfield, start, page_len, filters): return webnotes.conn.sql("""select tabAccount.name from `tabAccount` where (tabAccount.debit_or_credit="Credit" - or tabAccount.account_type = "Income Account") - and tabAccount.group_or_ledger="Ledger" and tabAccount.docstatus!=2 - and tabAccount.company = '%(company)s' and tabAccount.%(key)s LIKE '%(txt)s' - %(mcond)s""" % {'company': filters['company'], 'key': searchfield, + or tabAccount.account_type = "Income Account") + and tabAccount.group_or_ledger="Ledger" + and tabAccount.docstatus!=2 + and tabAccount.company = '%(company)s' + and tabAccount.%(key)s LIKE '%(txt)s' + %(mcond)s""" % {'company': filters['company'], 'key': searchfield, 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield)}) \ No newline at end of file diff --git a/buying/doctype/quality_inspection/quality_inspection.js b/buying/doctype/quality_inspection/quality_inspection.js index 72eaecb5a1..d40d81a4fa 100644 --- a/buying/doctype/quality_inspection/quality_inspection.js +++ b/buying/doctype/quality_inspection/quality_inspection.js @@ -43,15 +43,11 @@ cur_frm.cscript.refresh = cur_frm.cscript.inspection_type; // item code based on GRN/DN cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { - filter = {}; - if (doc.purchase_receipt_no) - filter:{ - 'parent': doc.purchase_receipt_no - } - else if (doc.delivery_note_no) - filter:{ - 'parent': doc.delivery_note_no - } + var filter = {}; + if (doc.purchase_receipt_no) filter['parent'] = doc.purchase_receipt_no; + + else if (doc.delivery_note_no) filter['parent'] = doc.delivery_note_no; + return{ filters: filter } @@ -59,15 +55,14 @@ cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { // Serial No based on item_code cur_frm.fields_dict['item_serial_no'].get_query = function(doc, cdt, cdn) { - filter = {}; + var filter = {}; if (doc.item_code) filter:{ 'item_code': doc.item_code, 'status': "In Store" } - // return 'SELECT name, item_code, warehouse FROM `tabSerial No` WHERE docstatus != 2 AND item_code = "' + doc.item_code +'" AND status = "In Store" AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; else - filter:{ 'status': "In Store" } - // return 'SELECT name, item_code, warehouse FROM `tabSerial No` WHERE docstatus != 2 AND status = "In Store" AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; - return{ filters: filter } + filter: { 'status': "In Store" } + + return { filters: filter } } \ No newline at end of file diff --git a/buying/doctype/supplier_quotation/supplier_quotation.js b/buying/doctype/supplier_quotation/supplier_quotation.js index 54ef722885..722ac002a0 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/buying/doctype/supplier_quotation/supplier_quotation.js @@ -67,7 +67,7 @@ cur_frm.fields_dict['quotation_items'].grid.get_field('project_name').get_query function(doc, cdt, cdn) { return{ filters:[ - ['Project', 'status', 'not in', 'Completed, Cancelled'], + ['Project', 'status', 'not in', 'Completed, Cancelled'] ] } } diff --git a/projects/doctype/task/task.py b/projects/doctype/task/task.py index 0072b1f70d..0ea9eea1eb 100644 --- a/projects/doctype/task/task.py +++ b/projects/doctype/task/task.py @@ -96,8 +96,9 @@ def get_events(start, end, filters=None): 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 + 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/opportunity/opportunity.py b/selling/doctype/opportunity/opportunity.py index 6217821499..92d391b2de 100644 --- a/selling/doctype/opportunity/opportunity.py +++ b/selling/doctype/opportunity/opportunity.py @@ -207,8 +207,9 @@ def make_quotation(source_name, target_doclist=None): 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 + 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 cfaf61172a..0649f54512 100644 --- a/selling/doctype/quotation/quotation.js +++ b/selling/doctype/quotation/quotation.js @@ -199,7 +199,7 @@ cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query= return { query: 'selling.doctype.quotation.quotation.quotation_details', filters:{ - cond: cond, + cond: cond } } } diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index 152e909a2b..5bf8510a0a 100644 --- a/selling/doctype/quotation/quotation.py +++ b/selling/doctype/quotation/quotation.py @@ -266,26 +266,35 @@ def quotation_details(doctype, txt, searchfield, start, page_len, filters): 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)) + (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" + 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)) + (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" + 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}) + 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 + return 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_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index dfbfb48958..00825bb265 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -370,20 +370,30 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters): if filters.has_key('warehouse'): return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle - where item_code = '%(item_code)s' and warehouse = '%(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 + where item_code = '%(item_code)s' + and warehouse = '%(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'], 'warehouse': filters['warehouse'], - 'posting_date': filters['posting_date'], 'txt': 'txt': "%%%s%%" % txt, - 'mcond':get_match_cond(doctype, searchfield),'start': start, 'page_len': page_len}) + order by batch_no desc + limit %(start)s, %(page_len)s """ % {'item_code': filters['item_code'], + 'warehouse': filters['warehouse'], 'posting_date': filters['posting_date'], + 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), + 'start': start, 'page_len': page_len}) else: - return webnotes.conn.sql("""select name from tabBatch where docstatus != 2 - and item = '%(item_code)s' and expiry_date >= '%(posting_date)s' - and name like '%(txt)s' %(mcond)s ORDER BY name DESC LIMIT 50""" % - {'item_code': filters['item_code'], 'posting_date': filters['posting_date'], - 'txt': 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), - 'start': start, 'page_len': page_len}) \ No newline at end of file + return webnotes.conn.sql("""select name from tabBatch + where docstatus != 2 + and item = '%(item_code)s' + and expiry_date >= '%(posting_date)s' + and name like '%(txt)s' + %(mcond)s + order by name desc + limit %(start)s, %(page_len)s""" % {'item_code': filters['item_code'], + 'posting_date': filters['posting_date'], 'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield),'start': start, + 'page_len': page_len}) \ No newline at end of file diff --git a/stock/doctype/packing_slip/packing_slip.py b/stock/doctype/packing_slip/packing_slip.py index a46d77c696..63aa6a9431 100644 --- a/stock/doctype/packing_slip/packing_slip.py +++ b/stock/doctype/packing_slip/packing_slip.py @@ -177,7 +177,9 @@ 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", + 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/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index fc4fadcf18..d985432b84 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -717,7 +717,8 @@ def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters): 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 %s + and (`%s` like %%(txt)s + or `customer` like %%(txt)s) %s %s order by name, customer, customer_name limit %s""" % (doctype, searchfield, conditions, get_match_cond(doctype, searchfield), "%(start)s, %(page_len)s"), @@ -728,7 +729,8 @@ def query_purchase_return_doc(doctype, txt, searchfield, start, page_len, filter 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) %s + and (`%s` like %%(txt)s + or `supplier` like %%(txt)s) %s order by name, supplier, supplier_name limit %s""" % (doctype, searchfield, get_match_cond(doctype, searchfield), "%(start)s, %(page_len)s"), {"txt": "%%%s%%" % txt, "start": @@ -762,15 +764,21 @@ 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}) + 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""" diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.py b/support/doctype/maintenance_schedule/maintenance_schedule.py index 6260acd74b..56dceaa146 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -335,12 +335,16 @@ def make_maintenance_visit(source_name, target_doclist=None): 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 + 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