From 028755941eeb1d31a5d3672c290caf5b11f22e85 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 8 Jul 2013 18:45:55 +0530 Subject: [PATCH] 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)