Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 5 | import frappe |
Deepesh Garg | fbf6e56 | 2020-03-31 10:45:32 +0530 | [diff] [blame] | 6 | import erpnext |
Rushabh Mehta | b92087c | 2017-01-13 18:53:11 +0530 | [diff] [blame] | 7 | from frappe.desk.reportview import get_match_cond, get_filters_cond |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 8 | from frappe.utils import nowdate, getdate |
suyashphadtare | 750a067 | 2017-01-18 15:35:01 +0530 | [diff] [blame] | 9 | from collections import defaultdict |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 10 | from erpnext.stock.get_item_details import _get_item_tax_template |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 11 | from frappe.utils import unique |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 12 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 13 | # searches for active employees |
| 14 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 15 | @frappe.validate_and_sanitize_search_inputs |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 16 | def employee_query(doctype, txt, searchfield, start, page_len, filters): |
Kanchan Chauhan | 7652b85 | 2016-11-16 15:29:01 +0530 | [diff] [blame] | 17 | conditions = [] |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 18 | fields = get_fields("Employee", ["name", "employee_name"]) |
| 19 | |
| 20 | return frappe.db.sql("""select {fields} from `tabEmployee` |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 21 | where status = 'Active' |
| 22 | and docstatus < 2 |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 23 | and ({key} like %(txt)s |
| 24 | or employee_name like %(txt)s) |
Kanchan Chauhan | 7652b85 | 2016-11-16 15:29:01 +0530 | [diff] [blame] | 25 | {fcond} {mcond} |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 26 | order by |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 27 | if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), |
| 28 | if(locate(%(_txt)s, employee_name), locate(%(_txt)s, employee_name), 99999), |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 29 | idx desc, |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 30 | name, employee_name |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 31 | limit %(start)s, %(page_len)s""".format(**{ |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 32 | 'fields': ", ".join(fields), |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 33 | 'key': searchfield, |
Kanchan Chauhan | 7652b85 | 2016-11-16 15:29:01 +0530 | [diff] [blame] | 34 | 'fcond': get_filters_cond(doctype, filters, conditions), |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 35 | 'mcond': get_match_cond(doctype) |
| 36 | }), { |
| 37 | 'txt': "%%%s%%" % txt, |
| 38 | '_txt': txt.replace("%", ""), |
| 39 | 'start': start, |
| 40 | 'page_len': page_len |
| 41 | }) |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 42 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 43 | |
| 44 | # searches for leads which are not converted |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 45 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 46 | @frappe.validate_and_sanitize_search_inputs |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 47 | def lead_query(doctype, txt, searchfield, start, page_len, filters): |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 48 | fields = get_fields("Lead", ["name", "lead_name", "company_name"]) |
| 49 | |
| 50 | return frappe.db.sql("""select {fields} from `tabLead` |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 51 | where docstatus < 2 |
| 52 | and ifnull(status, '') != 'Converted' |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 53 | and ({key} like %(txt)s |
| 54 | or lead_name like %(txt)s |
| 55 | or company_name like %(txt)s) |
| 56 | {mcond} |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 57 | order by |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 58 | if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), |
| 59 | if(locate(%(_txt)s, lead_name), locate(%(_txt)s, lead_name), 99999), |
| 60 | if(locate(%(_txt)s, company_name), locate(%(_txt)s, company_name), 99999), |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 61 | idx desc, |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 62 | name, lead_name |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 63 | limit %(start)s, %(page_len)s""".format(**{ |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 64 | 'fields': ", ".join(fields), |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 65 | 'key': searchfield, |
| 66 | 'mcond':get_match_cond(doctype) |
| 67 | }), { |
| 68 | 'txt': "%%%s%%" % txt, |
| 69 | '_txt': txt.replace("%", ""), |
| 70 | 'start': start, |
| 71 | 'page_len': page_len |
| 72 | }) |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 73 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 74 | |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 75 | # searches for customer |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 76 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 77 | @frappe.validate_and_sanitize_search_inputs |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 78 | def customer_query(doctype, txt, searchfield, start, page_len, filters): |
KanchanChauhan | 4b888b9 | 2017-07-25 14:03:01 +0530 | [diff] [blame] | 79 | conditions = [] |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 80 | cust_master_name = frappe.defaults.get_user_default("cust_master_name") |
Saurabh | f52dc07 | 2013-07-10 13:07:49 +0530 | [diff] [blame] | 81 | |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 82 | if cust_master_name == "Customer Name": |
| 83 | fields = ["name", "customer_group", "territory"] |
| 84 | else: |
| 85 | fields = ["name", "customer_name", "customer_group", "territory"] |
Rushabh Mehta | b92087c | 2017-01-13 18:53:11 +0530 | [diff] [blame] | 86 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 87 | fields = get_fields("Customer", fields) |
Saurabh | f52dc07 | 2013-07-10 13:07:49 +0530 | [diff] [blame] | 88 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 89 | searchfields = frappe.get_meta("Customer").get_search_fields() |
Console Admin | 8623166 | 2017-06-23 20:32:52 +0300 | [diff] [blame] | 90 | searchfields = " or ".join([field + " like %(txt)s" for field in searchfields]) |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 91 | |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 92 | return frappe.db.sql("""select {fields} from `tabCustomer` |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 93 | where docstatus < 2 |
Console Admin | 8623166 | 2017-06-23 20:32:52 +0300 | [diff] [blame] | 94 | and ({scond}) and disabled=0 |
KanchanChauhan | 4b888b9 | 2017-07-25 14:03:01 +0530 | [diff] [blame] | 95 | {fcond} {mcond} |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 96 | order by |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 97 | if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), |
| 98 | if(locate(%(_txt)s, customer_name), locate(%(_txt)s, customer_name), 99999), |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 99 | idx desc, |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 100 | name, customer_name |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 101 | limit %(start)s, %(page_len)s""".format(**{ |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 102 | "fields": ", ".join(fields), |
Console Admin | 8623166 | 2017-06-23 20:32:52 +0300 | [diff] [blame] | 103 | "scond": searchfields, |
KanchanChauhan | 4b888b9 | 2017-07-25 14:03:01 +0530 | [diff] [blame] | 104 | "mcond": get_match_cond(doctype), |
| 105 | "fcond": get_filters_cond(doctype, filters, conditions).replace('%', '%%'), |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 106 | }), { |
| 107 | 'txt': "%%%s%%" % txt, |
| 108 | '_txt': txt.replace("%", ""), |
| 109 | 'start': start, |
| 110 | 'page_len': page_len |
| 111 | }) |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 112 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 113 | |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 114 | # searches for supplier |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 115 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 116 | @frappe.validate_and_sanitize_search_inputs |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 117 | def supplier_query(doctype, txt, searchfield, start, page_len, filters): |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 118 | supp_master_name = frappe.defaults.get_user_default("supp_master_name") |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 119 | |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 120 | if supp_master_name == "Supplier Name": |
Zlash65 | 2e08098 | 2018-04-19 18:37:53 +0530 | [diff] [blame] | 121 | fields = ["name", "supplier_group"] |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 122 | else: |
Zlash65 | 2e08098 | 2018-04-19 18:37:53 +0530 | [diff] [blame] | 123 | fields = ["name", "supplier_name", "supplier_group"] |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 124 | |
| 125 | fields = get_fields("Supplier", fields) |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 126 | |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 127 | return frappe.db.sql("""select {field} from `tabSupplier` |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 128 | where docstatus < 2 |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 129 | and ({key} like %(txt)s |
shreyas | 29b565f | 2016-01-25 17:30:49 +0530 | [diff] [blame] | 130 | or supplier_name like %(txt)s) and disabled=0 |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 131 | {mcond} |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 132 | order by |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 133 | if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), |
| 134 | if(locate(%(_txt)s, supplier_name), locate(%(_txt)s, supplier_name), 99999), |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 135 | idx desc, |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 136 | name, supplier_name |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 137 | limit %(start)s, %(page_len)s """.format(**{ |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 138 | 'field': ', '.join(fields), |
Anand Doshi | 48d3b54 | 2014-07-09 13:15:03 +0530 | [diff] [blame] | 139 | 'key': searchfield, |
| 140 | 'mcond':get_match_cond(doctype) |
| 141 | }), { |
| 142 | 'txt': "%%%s%%" % txt, |
| 143 | '_txt': txt.replace("%", ""), |
| 144 | 'start': start, |
| 145 | 'page_len': page_len |
| 146 | }) |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 147 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 148 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 149 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 150 | @frappe.validate_and_sanitize_search_inputs |
Nabin Hait | 9a380ef | 2013-07-16 17:24:17 +0530 | [diff] [blame] | 151 | def tax_account_query(doctype, txt, searchfield, start, page_len, filters): |
Deepesh Garg | fbf6e56 | 2020-03-31 10:45:32 +0530 | [diff] [blame] | 152 | company_currency = erpnext.get_company_currency(filters.get('company')) |
| 153 | |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 154 | def get_accounts(with_account_type_filter): |
| 155 | account_type_condition = '' |
| 156 | if with_account_type_filter: |
| 157 | account_type_condition = "AND account_type in %(account_types)s" |
| 158 | |
| 159 | accounts = frappe.db.sql(""" |
| 160 | SELECT name, parent_account |
| 161 | FROM `tabAccount` |
| 162 | WHERE `tabAccount`.docstatus!=2 |
| 163 | {account_type_condition} |
| 164 | AND is_group = 0 |
| 165 | AND company = %(company)s |
| 166 | AND account_currency = %(currency)s |
| 167 | AND `{searchfield}` LIKE %(txt)s |
prssanna | de7a2bc | 2020-09-21 13:57:04 +0530 | [diff] [blame] | 168 | {mcond} |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 169 | ORDER BY idx DESC, name |
| 170 | LIMIT %(offset)s, %(limit)s |
prssanna | de7a2bc | 2020-09-21 13:57:04 +0530 | [diff] [blame] | 171 | """.format( |
| 172 | account_type_condition=account_type_condition, |
| 173 | searchfield=searchfield, |
| 174 | mcond=get_match_cond(doctype) |
| 175 | ), |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 176 | dict( |
| 177 | account_types=filters.get("account_type"), |
| 178 | company=filters.get("company"), |
| 179 | currency=company_currency, |
| 180 | txt="%{}%".format(txt), |
| 181 | offset=start, |
| 182 | limit=page_len |
| 183 | ) |
| 184 | ) |
| 185 | |
| 186 | return accounts |
| 187 | |
| 188 | tax_accounts = get_accounts(True) |
| 189 | |
Nabin Hait | 0c21e2a | 2014-03-21 11:14:49 +0530 | [diff] [blame] | 190 | if not tax_accounts: |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 191 | tax_accounts = get_accounts(False) |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 192 | |
Nabin Hait | 0c21e2a | 2014-03-21 11:14:49 +0530 | [diff] [blame] | 193 | return tax_accounts |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 194 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 195 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 196 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 197 | @frappe.validate_and_sanitize_search_inputs |
Rushabh Mehta | 203cc96 | 2016-04-07 15:25:43 +0530 | [diff] [blame] | 198 | def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False): |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 199 | conditions = [] |
Saurabh | f52dc07 | 2013-07-10 13:07:49 +0530 | [diff] [blame] | 200 | |
marination | 3dbef9d | 2019-10-28 15:48:10 +0530 | [diff] [blame] | 201 | #Get searchfields from meta and use in Item Link field query |
marination | 1e754b1 | 2019-10-30 18:33:44 +0530 | [diff] [blame] | 202 | meta = frappe.get_meta("Item", cached=True) |
marination | 3dbef9d | 2019-10-28 15:48:10 +0530 | [diff] [blame] | 203 | searchfields = meta.get_search_fields() |
| 204 | |
marination | 1e754b1 | 2019-10-30 18:33:44 +0530 | [diff] [blame] | 205 | if "description" in searchfields: |
| 206 | searchfields.remove("description") |
noahjacob | ca2fb47 | 2021-05-12 16:25:07 +0530 | [diff] [blame] | 207 | |
Rohit Waghchaure | c42312e | 2019-11-19 19:05:23 +0530 | [diff] [blame] | 208 | columns = '' |
| 209 | extra_searchfields = [field for field in searchfields |
| 210 | if not field in ["name", "item_group", "description"]] |
| 211 | |
| 212 | if extra_searchfields: |
| 213 | columns = ", " + ", ".join(extra_searchfields) |
marination | 1e754b1 | 2019-10-30 18:33:44 +0530 | [diff] [blame] | 214 | |
| 215 | searchfields = searchfields + [field for field in[searchfield or "name", "item_code", "item_group", "item_name"] |
| 216 | if not field in searchfields] |
marination | 3dbef9d | 2019-10-28 15:48:10 +0530 | [diff] [blame] | 217 | searchfields = " or ".join([field + " like %(txt)s" for field in searchfields]) |
| 218 | |
noahjacob | ca2fb47 | 2021-05-12 16:25:07 +0530 | [diff] [blame] | 219 | if filters.get('supplier'): |
noahjacob | 8e34c49 | 2021-05-19 13:51:36 +0530 | [diff] [blame] | 220 | item_group_list = frappe.get_all('Supplier Item Group', filters = {'supplier': filters.get('supplier')}, fields = ['item_group']) |
noahjacob | ca2fb47 | 2021-05-12 16:25:07 +0530 | [diff] [blame] | 221 | |
| 222 | item_groups = [] |
| 223 | for i in item_group_list: |
| 224 | item_groups.append(i.item_group) |
| 225 | |
| 226 | del filters['supplier'] |
| 227 | |
| 228 | if item_groups: |
| 229 | filters['item_group'] = ['in', item_groups] |
| 230 | |
Rushabh Mehta | d5f9ebd | 2018-04-02 23:37:33 +0530 | [diff] [blame] | 231 | description_cond = '' |
| 232 | if frappe.db.count('Item', cache=True) < 50000: |
| 233 | # scan description only if items are less than 50000 |
| 234 | description_cond = 'or tabItem.description LIKE %(txt)s' |
Prateeksha Singh | 984a7a7 | 2018-05-17 17:29:36 +0530 | [diff] [blame] | 235 | return frappe.db.sql("""select tabItem.name, |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 236 | if(length(tabItem.item_name) > 40, |
| 237 | concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name, |
Prateeksha Singh | 984a7a7 | 2018-05-17 17:29:36 +0530 | [diff] [blame] | 238 | tabItem.item_group, |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 239 | if(length(tabItem.description) > 40, \ |
Rohit Waghchaure | c42312e | 2019-11-19 19:05:23 +0530 | [diff] [blame] | 240 | concat(substr(tabItem.description, 1, 40), "..."), description) as description |
marination | 1e754b1 | 2019-10-30 18:33:44 +0530 | [diff] [blame] | 241 | {columns} |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 242 | from tabItem |
Anand Doshi | 22c0d78 | 2013-11-04 16:23:04 +0530 | [diff] [blame] | 243 | where tabItem.docstatus < 2 |
Anand Doshi | 21e09a2 | 2015-10-29 12:21:41 +0530 | [diff] [blame] | 244 | and tabItem.disabled=0 |
rohitwaghchaure | 7978907 | 2020-05-21 18:10:13 +0530 | [diff] [blame] | 245 | and tabItem.has_variants=0 |
Rushabh Mehta | 864d1ea | 2014-06-23 12:20:12 +0530 | [diff] [blame] | 246 | and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00') |
marination | 3dbef9d | 2019-10-28 15:48:10 +0530 | [diff] [blame] | 247 | and ({scond} or tabItem.item_code IN (select parent from `tabItem Barcode` where barcode LIKE %(txt)s) |
Rohit Waghchaure | 2bfb063 | 2019-03-02 21:47:55 +0530 | [diff] [blame] | 248 | {description_cond}) |
Anand Doshi | 22c0d78 | 2013-11-04 16:23:04 +0530 | [diff] [blame] | 249 | {fcond} {mcond} |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 250 | order by |
| 251 | if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), |
| 252 | if(locate(%(_txt)s, item_name), locate(%(_txt)s, item_name), 99999), |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 253 | idx desc, |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 254 | name, item_name |
Rushabh Mehta | bc4e2cd | 2017-10-17 12:30:34 +0530 | [diff] [blame] | 255 | limit %(start)s, %(page_len)s """.format( |
marination | 1e754b1 | 2019-10-30 18:33:44 +0530 | [diff] [blame] | 256 | columns=columns, |
marination | 3dbef9d | 2019-10-28 15:48:10 +0530 | [diff] [blame] | 257 | scond=searchfields, |
Nabin Hait | c628506 | 2016-03-30 13:10:25 +0530 | [diff] [blame] | 258 | fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'), |
Rushabh Mehta | d5f9ebd | 2018-04-02 23:37:33 +0530 | [diff] [blame] | 259 | mcond=get_match_cond(doctype).replace('%', '%%'), |
| 260 | description_cond = description_cond), |
Anand Doshi | 22c0d78 | 2013-11-04 16:23:04 +0530 | [diff] [blame] | 261 | { |
| 262 | "today": nowdate(), |
| 263 | "txt": "%%%s%%" % txt, |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 264 | "_txt": txt.replace("%", ""), |
Anand Doshi | 22c0d78 | 2013-11-04 16:23:04 +0530 | [diff] [blame] | 265 | "start": start, |
| 266 | "page_len": page_len |
Rushabh Mehta | 203cc96 | 2016-04-07 15:25:43 +0530 | [diff] [blame] | 267 | }, as_dict=as_dict) |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 268 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 269 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 270 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 271 | @frappe.validate_and_sanitize_search_inputs |
Saurabh | 022ab63 | 2017-11-10 15:06:02 +0530 | [diff] [blame] | 272 | def bom(doctype, txt, searchfield, start, page_len, filters): |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 273 | conditions = [] |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 274 | fields = get_fields("BOM", ["name", "item"]) |
Saurabh | f52dc07 | 2013-07-10 13:07:49 +0530 | [diff] [blame] | 275 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 276 | return frappe.db.sql("""select {fields} |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 277 | from tabBOM |
| 278 | where tabBOM.docstatus=1 |
| 279 | and tabBOM.is_active=1 |
Nabin Hait | 6221117 | 2016-03-16 16:22:03 +0530 | [diff] [blame] | 280 | and tabBOM.`{key}` like %(txt)s |
| 281 | {fcond} {mcond} |
| 282 | order by |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 283 | if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), |
| 284 | idx desc, name |
Nabin Hait | 6221117 | 2016-03-16 16:22:03 +0530 | [diff] [blame] | 285 | limit %(start)s, %(page_len)s """.format( |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 286 | fields=", ".join(fields), |
Mangesh-Khairnar | 6a79691 | 2019-07-08 10:40:40 +0530 | [diff] [blame] | 287 | fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'), |
Karthikeyan S | 747c262 | 2019-07-19 22:49:21 +0530 | [diff] [blame] | 288 | mcond=get_match_cond(doctype).replace('%', '%%'), |
| 289 | key=searchfield), |
Mangesh-Khairnar | 6a79691 | 2019-07-08 10:40:40 +0530 | [diff] [blame] | 290 | { |
Karthikeyan S | 747c262 | 2019-07-19 22:49:21 +0530 | [diff] [blame] | 291 | 'txt': '%' + txt + '%', |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 292 | '_txt': txt.replace("%", ""), |
Saurabh | 022ab63 | 2017-11-10 15:06:02 +0530 | [diff] [blame] | 293 | 'start': start or 0, |
| 294 | 'page_len': page_len or 20 |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 295 | }) |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 296 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 297 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 298 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 299 | @frappe.validate_and_sanitize_search_inputs |
Saurabh | 0287559 | 2013-07-08 18:45:55 +0530 | [diff] [blame] | 300 | def get_project_name(doctype, txt, searchfield, start, page_len, filters): |
| 301 | cond = '' |
Nabin Hait | f71011a | 2014-08-21 11:34:31 +0530 | [diff] [blame] | 302 | if filters.get('customer'): |
Suraj Shetty | 6ea3de9 | 2018-09-26 18:15:53 +0530 | [diff] [blame] | 303 | cond = """(`tabProject`.customer = %s or |
rohitwaghchaure | e330472 | 2018-08-27 11:43:57 +0530 | [diff] [blame] | 304 | ifnull(`tabProject`.customer,"")="") and""" %(frappe.db.escape(filters.get("customer"))) |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 305 | |
Rucha Mahabal | 062d301 | 2021-05-07 13:31:14 +0530 | [diff] [blame] | 306 | fields = get_fields("Project", ["name", "project_name"]) |
| 307 | searchfields = frappe.get_meta("Project").get_search_fields() |
| 308 | searchfields = " or ".join([field + " like %(txt)s" for field in searchfields]) |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 309 | |
| 310 | return frappe.db.sql("""select {fields} from `tabProject` |
Rucha Mahabal | 062d301 | 2021-05-07 13:31:14 +0530 | [diff] [blame] | 311 | where |
| 312 | `tabProject`.status not in ("Completed", "Cancelled") |
| 313 | and {cond} {match_cond} {scond} |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 314 | order by |
| 315 | if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), |
| 316 | idx desc, |
| 317 | `tabProject`.name asc |
| 318 | limit {start}, {page_len}""".format( |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 319 | fields=", ".join(['`tabProject`.{0}'.format(f) for f in fields]), |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 320 | cond=cond, |
Rucha Mahabal | 062d301 | 2021-05-07 13:31:14 +0530 | [diff] [blame] | 321 | scond=searchfields, |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 322 | match_cond=get_match_cond(doctype), |
| 323 | start=start, |
| 324 | page_len=page_len), { |
| 325 | "txt": "%{0}%".format(txt), |
Nabin Hait | df4deba | 2016-03-16 11:16:31 +0530 | [diff] [blame] | 326 | "_txt": txt.replace('%', '') |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 327 | }) |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 328 | |
tundebabzy | f6d738b | 2017-09-18 12:40:09 +0100 | [diff] [blame] | 329 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 330 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 331 | @frappe.validate_and_sanitize_search_inputs |
Nabin Hait | 1e2d7b3 | 2017-05-17 13:52:21 +0530 | [diff] [blame] | 332 | def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len, filters, as_dict): |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 333 | fields = get_fields("Delivery Note", ["name", "customer", "posting_date"]) |
| 334 | |
Nabin Hait | 1e2d7b3 | 2017-05-17 13:52:21 +0530 | [diff] [blame] | 335 | return frappe.db.sql(""" |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 336 | select %(fields)s |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 337 | from `tabDelivery Note` |
| 338 | where `tabDelivery Note`.`%(key)s` like %(txt)s and |
tundebabzy | f6d738b | 2017-09-18 12:40:09 +0100 | [diff] [blame] | 339 | `tabDelivery Note`.docstatus = 1 |
Nabin Hait | 1e2d7b3 | 2017-05-17 13:52:21 +0530 | [diff] [blame] | 340 | and status not in ("Stopped", "Closed") %(fcond)s |
tundebabzy | f6d738b | 2017-09-18 12:40:09 +0100 | [diff] [blame] | 341 | and ( |
| 342 | (`tabDelivery Note`.is_return = 0 and `tabDelivery Note`.per_billed < 100) |
Deepesh Garg | e2dc102 | 2021-04-14 11:21:11 +0530 | [diff] [blame] | 343 | or (`tabDelivery Note`.grand_total = 0 and `tabDelivery Note`.per_billed < 100) |
tundebabzy | f6d738b | 2017-09-18 12:40:09 +0100 | [diff] [blame] | 344 | or ( |
| 345 | `tabDelivery Note`.is_return = 1 |
| 346 | and return_against in (select name from `tabDelivery Note` where per_billed < 100) |
| 347 | ) |
| 348 | ) |
rohitwaghchaure | d07a3e1 | 2019-05-15 07:46:28 +0530 | [diff] [blame] | 349 | %(mcond)s order by `tabDelivery Note`.`%(key)s` asc limit %(start)s, %(page_len)s |
Nabin Hait | 1e2d7b3 | 2017-05-17 13:52:21 +0530 | [diff] [blame] | 350 | """ % { |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 351 | "fields": ", ".join(["`tabDelivery Note`.{0}".format(f) for f in fields]), |
Nabin Hait | 1e2d7b3 | 2017-05-17 13:52:21 +0530 | [diff] [blame] | 352 | "key": searchfield, |
| 353 | "fcond": get_filters_cond(doctype, filters, []), |
| 354 | "mcond": get_match_cond(doctype), |
rohitwaghchaure | d07a3e1 | 2019-05-15 07:46:28 +0530 | [diff] [blame] | 355 | "start": start, |
| 356 | "page_len": page_len, |
Nabin Hait | 1e2d7b3 | 2017-05-17 13:52:21 +0530 | [diff] [blame] | 357 | "txt": "%(txt)s" |
tundebabzy | f6d738b | 2017-09-18 12:40:09 +0100 | [diff] [blame] | 358 | }, {"txt": ("%%%s%%" % txt)}, as_dict=as_dict) |
| 359 | |
Nabin Hait | d1fd1e2 | 2013-10-18 12:29:11 +0530 | [diff] [blame] | 360 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 361 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 362 | @frappe.validate_and_sanitize_search_inputs |
Nabin Hait | d1fd1e2 | 2013-10-18 12:29:11 +0530 | [diff] [blame] | 363 | def get_batch_no(doctype, txt, searchfield, start, page_len, filters): |
Neil Trini Lasrado | ebb60f5 | 2015-07-08 14:36:09 +0530 | [diff] [blame] | 364 | cond = "" |
| 365 | if filters.get("posting_date"): |
Nabin Hait | 7918b92 | 2018-01-31 15:30:03 +0530 | [diff] [blame] | 366 | cond = "and (batch.expiry_date is null or batch.expiry_date >= %(posting_date)s)" |
Rushabh Mehta | b6398be | 2015-08-26 10:50:16 +0530 | [diff] [blame] | 367 | |
Nabin Hait | 2ed71ba | 2015-03-20 15:06:30 +0530 | [diff] [blame] | 368 | batch_nos = None |
| 369 | args = { |
| 370 | 'item_code': filters.get("item_code"), |
| 371 | 'warehouse': filters.get("warehouse"), |
| 372 | 'posting_date': filters.get('posting_date'), |
Anand Doshi | 0dc79f4 | 2015-04-06 12:59:34 +0530 | [diff] [blame] | 373 | 'txt': "%{0}%".format(txt), |
Nabin Hait | 2ed71ba | 2015-03-20 15:06:30 +0530 | [diff] [blame] | 374 | "start": start, |
| 375 | "page_len": page_len |
| 376 | } |
| 377 | |
Rohit Waghchaure | d8ddd1e | 2019-10-22 14:03:27 +0530 | [diff] [blame] | 378 | having_clause = "having sum(sle.actual_qty) > 0" |
| 379 | if filters.get("is_return"): |
| 380 | having_clause = "" |
| 381 | |
Deepesh Garg | a0d192e | 2020-09-22 13:54:07 +0530 | [diff] [blame] | 382 | meta = frappe.get_meta("Batch", cached=True) |
| 383 | searchfields = meta.get_search_fields() |
| 384 | |
| 385 | search_columns = '' |
Deepesh Garg | f58a5ec | 2020-10-05 13:55:53 +0530 | [diff] [blame] | 386 | search_cond = '' |
| 387 | |
Deepesh Garg | a0d192e | 2020-09-22 13:54:07 +0530 | [diff] [blame] | 388 | if searchfields: |
| 389 | search_columns = ", " + ", ".join(searchfields) |
Deepesh Garg | 1fae774 | 2020-10-05 12:38:54 +0530 | [diff] [blame] | 390 | search_cond = " or " + " or ".join([field + " like %(txt)s" for field in searchfields]) |
Deepesh Garg | a0d192e | 2020-09-22 13:54:07 +0530 | [diff] [blame] | 391 | |
Anand Doshi | 0dc79f4 | 2015-04-06 12:59:34 +0530 | [diff] [blame] | 392 | if args.get('warehouse'): |
Deepesh Garg | a0d192e | 2020-09-22 13:54:07 +0530 | [diff] [blame] | 393 | searchfields = ['batch.' + field for field in searchfields] |
| 394 | if searchfields: |
| 395 | search_columns = ", " + ", ".join(searchfields) |
Deepesh Garg | 1fae774 | 2020-10-05 12:38:54 +0530 | [diff] [blame] | 396 | search_cond = " or " + " or ".join([field + " like %(txt)s" for field in searchfields]) |
Deepesh Garg | a0d192e | 2020-09-22 13:54:07 +0530 | [diff] [blame] | 397 | |
Rohit Waghchaure | d8ddd1e | 2019-10-22 14:03:27 +0530 | [diff] [blame] | 398 | batch_nos = frappe.db.sql("""select sle.batch_no, round(sum(sle.actual_qty),2), sle.stock_uom, |
| 399 | concat('MFG-',batch.manufacturing_date), concat('EXP-',batch.expiry_date) |
Deepesh Garg | a0d192e | 2020-09-22 13:54:07 +0530 | [diff] [blame] | 400 | {search_columns} |
Rohit Waghchaure | d8ddd1e | 2019-10-22 14:03:27 +0530 | [diff] [blame] | 401 | from `tabStock Ledger Entry` sle |
| 402 | INNER JOIN `tabBatch` batch on sle.batch_no = batch.name |
| 403 | where |
| 404 | batch.disabled = 0 |
| 405 | and sle.item_code = %(item_code)s |
| 406 | and sle.warehouse = %(warehouse)s |
| 407 | and (sle.batch_no like %(txt)s |
Sun Howwrongbum | 088be37 | 2019-12-24 12:29:25 +0530 | [diff] [blame] | 408 | or batch.expiry_date like %(txt)s |
Deepesh Garg | f58a5ec | 2020-10-05 13:55:53 +0530 | [diff] [blame] | 409 | or batch.manufacturing_date like %(txt)s |
| 410 | {search_cond}) |
Rohit Waghchaure | d8ddd1e | 2019-10-22 14:03:27 +0530 | [diff] [blame] | 411 | and batch.docstatus < 2 |
| 412 | {cond} |
| 413 | {match_conditions} |
| 414 | group by batch_no {having_clause} |
| 415 | order by batch.expiry_date, sle.batch_no desc |
| 416 | limit %(start)s, %(page_len)s""".format( |
Deepesh Garg | a0d192e | 2020-09-22 13:54:07 +0530 | [diff] [blame] | 417 | search_columns = search_columns, |
Rohit Waghchaure | d8ddd1e | 2019-10-22 14:03:27 +0530 | [diff] [blame] | 418 | cond=cond, |
| 419 | match_conditions=get_match_cond(doctype), |
Deepesh Garg | 1fae774 | 2020-10-05 12:38:54 +0530 | [diff] [blame] | 420 | having_clause = having_clause, |
| 421 | search_cond = search_cond |
Rohit Waghchaure | d8ddd1e | 2019-10-22 14:03:27 +0530 | [diff] [blame] | 422 | ), args) |
Nabin Hait | 2ed71ba | 2015-03-20 15:06:30 +0530 | [diff] [blame] | 423 | |
Nabin Hait | 2ed71ba | 2015-03-20 15:06:30 +0530 | [diff] [blame] | 424 | return batch_nos |
Nabin Hait | d1fd1e2 | 2013-10-18 12:29:11 +0530 | [diff] [blame] | 425 | else: |
Deepesh Garg | a0d192e | 2020-09-22 13:54:07 +0530 | [diff] [blame] | 426 | return frappe.db.sql("""select name, concat('MFG-', manufacturing_date), concat('EXP-',expiry_date) |
| 427 | {search_columns} |
| 428 | from `tabBatch` batch |
Doridel Cahanap | 59e4c32 | 2018-08-06 17:15:18 +0800 | [diff] [blame] | 429 | where batch.disabled = 0 |
| 430 | and item = %(item_code)s |
sivankar | 621740e | 2018-02-12 14:33:40 +0530 | [diff] [blame] | 431 | and (name like %(txt)s |
Sun Howwrongbum | 088be37 | 2019-12-24 12:29:25 +0530 | [diff] [blame] | 432 | or expiry_date like %(txt)s |
Deepesh Garg | f58a5ec | 2020-10-05 13:55:53 +0530 | [diff] [blame] | 433 | or manufacturing_date like %(txt)s |
| 434 | {search_cond}) |
Nabin Hait | 2ed71ba | 2015-03-20 15:06:30 +0530 | [diff] [blame] | 435 | and docstatus < 2 |
Neil Trini Lasrado | ebb60f5 | 2015-07-08 14:36:09 +0530 | [diff] [blame] | 436 | {0} |
Anand Doshi | 0dc79f4 | 2015-04-06 12:59:34 +0530 | [diff] [blame] | 437 | {match_conditions} |
Deepesh Garg | f58a5ec | 2020-10-05 13:55:53 +0530 | [diff] [blame] | 438 | |
Anand Doshi | 0dc79f4 | 2015-04-06 12:59:34 +0530 | [diff] [blame] | 439 | order by expiry_date, name desc |
Deepesh Garg | 1fae774 | 2020-10-05 12:38:54 +0530 | [diff] [blame] | 440 | limit %(start)s, %(page_len)s""".format(cond, search_columns = search_columns, |
| 441 | search_cond = search_cond, match_conditions=get_match_cond(doctype)), args) |
Nabin Hait | ea4aa04 | 2014-05-28 12:56:28 +0530 | [diff] [blame] | 442 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 443 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 444 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 445 | @frappe.validate_and_sanitize_search_inputs |
Nabin Hait | ea4aa04 | 2014-05-28 12:56:28 +0530 | [diff] [blame] | 446 | def get_account_list(doctype, txt, searchfield, start, page_len, filters): |
Nabin Hait | e1b2b3e | 2014-06-14 15:26:10 +0530 | [diff] [blame] | 447 | filter_list = [] |
Nabin Hait | ea4aa04 | 2014-05-28 12:56:28 +0530 | [diff] [blame] | 448 | |
Nabin Hait | e1b2b3e | 2014-06-14 15:26:10 +0530 | [diff] [blame] | 449 | if isinstance(filters, dict): |
| 450 | for key, val in filters.items(): |
| 451 | if isinstance(val, (list, tuple)): |
| 452 | filter_list.append([doctype, key, val[0], val[1]]) |
| 453 | else: |
| 454 | filter_list.append([doctype, key, "=", val]) |
bhupeshg2 | e2e973f | 2015-04-14 22:15:24 +0530 | [diff] [blame] | 455 | elif isinstance(filters, list): |
| 456 | filter_list.extend(filters) |
Nabin Hait | e1b2b3e | 2014-06-14 15:26:10 +0530 | [diff] [blame] | 457 | |
Rushabh Mehta | 38c6b52 | 2015-04-23 13:14:17 +0530 | [diff] [blame] | 458 | if "is_group" not in [d[1] for d in filter_list]: |
| 459 | filter_list.append(["Account", "is_group", "=", "0"]) |
Nabin Hait | e1b2b3e | 2014-06-14 15:26:10 +0530 | [diff] [blame] | 460 | |
| 461 | if searchfield and txt: |
| 462 | filter_list.append([doctype, searchfield, "like", "%%%s%%" % txt]) |
| 463 | |
Rushabh Mehta | c0bb453 | 2014-09-09 16:15:35 +0530 | [diff] [blame] | 464 | return frappe.desk.reportview.execute("Account", filters = filter_list, |
Nabin Hait | ea4aa04 | 2014-05-28 12:56:28 +0530 | [diff] [blame] | 465 | fields = ["name", "parent_account"], |
| 466 | limit_start=start, limit_page_length=page_len, as_list=True) |
Anand Doshi | faefeaa | 2014-06-24 18:53:04 +0530 | [diff] [blame] | 467 | |
Chinmay D. Pai | aa12109 | 2020-07-01 21:14:32 +0530 | [diff] [blame] | 468 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 469 | @frappe.validate_and_sanitize_search_inputs |
Marica | 299e217 | 2020-04-28 13:00:04 +0530 | [diff] [blame] | 470 | def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters): |
| 471 | return frappe.db.sql("""select distinct bo.name, bo.blanket_order_type, bo.to_date |
| 472 | from `tabBlanket Order` bo, `tabBlanket Order Item` boi |
| 473 | where |
| 474 | boi.parent = bo.name |
| 475 | and boi.item_code = {item_code} |
| 476 | and bo.blanket_order_type = '{blanket_order_type}' |
| 477 | and bo.company = {company} |
| 478 | and bo.docstatus = 1""" |
| 479 | .format(item_code = frappe.db.escape(filters.get("item")), |
| 480 | blanket_order_type = filters.get("blanket_order_type"), |
| 481 | company = frappe.db.escape(filters.get("company")) |
| 482 | )) |
Nabin Hait | afd14f6 | 2015-10-19 11:55:28 +0530 | [diff] [blame] | 483 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 484 | |
Nabin Hait | afd14f6 | 2015-10-19 11:55:28 +0530 | [diff] [blame] | 485 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 486 | @frappe.validate_and_sanitize_search_inputs |
Nabin Hait | afd14f6 | 2015-10-19 11:55:28 +0530 | [diff] [blame] | 487 | def get_income_account(doctype, txt, searchfield, start, page_len, filters): |
| 488 | from erpnext.controllers.queries import get_match_cond |
| 489 | |
| 490 | # income account can be any Credit account, |
| 491 | # but can also be a Asset account with account_type='Income Account' in special circumstances. |
| 492 | # Hence the first condition is an "OR" |
| 493 | if not filters: filters = {} |
| 494 | |
Anand Doshi | 21e09a2 | 2015-10-29 12:21:41 +0530 | [diff] [blame] | 495 | condition = "" |
Nabin Hait | afd14f6 | 2015-10-19 11:55:28 +0530 | [diff] [blame] | 496 | if filters.get("company"): |
| 497 | condition += "and tabAccount.company = %(company)s" |
Anand Doshi | 21e09a2 | 2015-10-29 12:21:41 +0530 | [diff] [blame] | 498 | |
Nabin Hait | afd14f6 | 2015-10-19 11:55:28 +0530 | [diff] [blame] | 499 | return frappe.db.sql("""select tabAccount.name from `tabAccount` |
| 500 | where (tabAccount.report_type = "Profit and Loss" |
| 501 | or tabAccount.account_type in ("Income Account", "Temporary")) |
| 502 | and tabAccount.is_group=0 |
| 503 | and tabAccount.`{key}` LIKE %(txt)s |
Rushabh Mehta | 3574b37 | 2016-03-11 14:33:04 +0530 | [diff] [blame] | 504 | {condition} {match_condition} |
| 505 | order by idx desc, name""" |
Nabin Hait | afd14f6 | 2015-10-19 11:55:28 +0530 | [diff] [blame] | 506 | .format(condition=condition, match_condition=get_match_cond(doctype), key=searchfield), { |
Suraj Shetty | 4b404c4 | 2018-09-27 15:39:34 +0530 | [diff] [blame] | 507 | 'txt': '%' + txt + '%', |
Nabin Hait | afd14f6 | 2015-10-19 11:55:28 +0530 | [diff] [blame] | 508 | 'company': filters.get("company", "") |
Anand Doshi | 21e09a2 | 2015-10-29 12:21:41 +0530 | [diff] [blame] | 509 | }) |
Nabin Hait | 3a15c92 | 2016-03-04 12:30:46 +0530 | [diff] [blame] | 510 | |
Deepesh Garg | 96e874b | 2020-11-15 22:43:01 +0530 | [diff] [blame] | 511 | @frappe.whitelist() |
| 512 | @frappe.validate_and_sanitize_search_inputs |
| 513 | def get_filtered_dimensions(doctype, txt, searchfield, start, page_len, filters): |
| 514 | from erpnext.accounts.doctype.accounting_dimension_filter.accounting_dimension_filter import get_dimension_filter_map |
| 515 | dimension_filters = get_dimension_filter_map() |
| 516 | dimension_filters = dimension_filters.get((filters.get('dimension'),filters.get('account'))) |
Deepesh Garg | 6c17b84 | 2020-11-25 13:42:16 +0530 | [diff] [blame] | 517 | query_filters = [] |
Deepesh Garg | 96e874b | 2020-11-15 22:43:01 +0530 | [diff] [blame] | 518 | |
| 519 | meta = frappe.get_meta(doctype) |
Deepesh Garg | 96e874b | 2020-11-15 22:43:01 +0530 | [diff] [blame] | 520 | if meta.is_tree: |
Deepesh Garg | 6c17b84 | 2020-11-25 13:42:16 +0530 | [diff] [blame] | 521 | query_filters.append(['is_group', '=', 0]) |
Deepesh Garg | 96e874b | 2020-11-15 22:43:01 +0530 | [diff] [blame] | 522 | |
| 523 | if meta.has_field('company'): |
Deepesh Garg | 6c17b84 | 2020-11-25 13:42:16 +0530 | [diff] [blame] | 524 | query_filters.append(['company', '=', filters.get('company')]) |
| 525 | |
| 526 | if txt: |
| 527 | query_filters.append([searchfield, 'LIKE', "%%%s%%" % txt]) |
Deepesh Garg | 96e874b | 2020-11-15 22:43:01 +0530 | [diff] [blame] | 528 | |
| 529 | if dimension_filters: |
| 530 | if dimension_filters['allow_or_restrict'] == 'Allow': |
| 531 | query_selector = 'in' |
| 532 | else: |
| 533 | query_selector = 'not in' |
| 534 | |
| 535 | if len(dimension_filters['allowed_dimensions']) == 1: |
| 536 | dimensions = tuple(dimension_filters['allowed_dimensions'] * 2) |
| 537 | else: |
| 538 | dimensions = tuple(dimension_filters['allowed_dimensions']) |
| 539 | |
Deepesh Garg | 6c17b84 | 2020-11-25 13:42:16 +0530 | [diff] [blame] | 540 | query_filters.append(['name', query_selector, dimensions]) |
Deepesh Garg | 96e874b | 2020-11-15 22:43:01 +0530 | [diff] [blame] | 541 | |
Deepesh Garg | 6c17b84 | 2020-11-25 13:42:16 +0530 | [diff] [blame] | 542 | output = frappe.get_all(doctype, filters=query_filters) |
| 543 | result = [d.name for d in output] |
| 544 | |
| 545 | return [(d,) for d in set(result)] |
Nabin Hait | 3a15c92 | 2016-03-04 12:30:46 +0530 | [diff] [blame] | 546 | |
| 547 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 548 | @frappe.validate_and_sanitize_search_inputs |
Nabin Hait | 3a15c92 | 2016-03-04 12:30:46 +0530 | [diff] [blame] | 549 | def get_expense_account(doctype, txt, searchfield, start, page_len, filters): |
| 550 | from erpnext.controllers.queries import get_match_cond |
Rushabh Mehta | 203cc96 | 2016-04-07 15:25:43 +0530 | [diff] [blame] | 551 | |
Nabin Hait | 3a15c92 | 2016-03-04 12:30:46 +0530 | [diff] [blame] | 552 | if not filters: filters = {} |
| 553 | |
| 554 | condition = "" |
| 555 | if filters.get("company"): |
| 556 | condition += "and tabAccount.company = %(company)s" |
Rushabh Mehta | 203cc96 | 2016-04-07 15:25:43 +0530 | [diff] [blame] | 557 | |
Nabin Hait | 3a15c92 | 2016-03-04 12:30:46 +0530 | [diff] [blame] | 558 | return frappe.db.sql("""select tabAccount.name from `tabAccount` |
| 559 | where (tabAccount.report_type = "Profit and Loss" |
Mangesh-Khairnar | 5619db2 | 2019-08-21 14:49:24 +0530 | [diff] [blame] | 560 | or tabAccount.account_type in ("Expense Account", "Fixed Asset", "Temporary", "Asset Received But Not Billed", "Capital Work in Progress")) |
Nabin Hait | 3a15c92 | 2016-03-04 12:30:46 +0530 | [diff] [blame] | 561 | and tabAccount.is_group=0 |
| 562 | and tabAccount.docstatus!=2 |
| 563 | and tabAccount.{key} LIKE %(txt)s |
| 564 | {condition} {match_condition}""" |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 565 | .format(condition=condition, key=searchfield, |
Nabin Hait | 3a15c92 | 2016-03-04 12:30:46 +0530 | [diff] [blame] | 566 | match_condition=get_match_cond(doctype)), { |
Neil Trini Lasrado | 30b97b0 | 2016-03-31 23:10:13 +0530 | [diff] [blame] | 567 | 'company': filters.get("company", ""), |
Suraj Shetty | 4b404c4 | 2018-09-27 15:39:34 +0530 | [diff] [blame] | 568 | 'txt': '%' + txt + '%' |
Maxwell Morais | 3557261 | 2016-07-21 23:42:59 -0300 | [diff] [blame] | 569 | }) |
suyashphadtare | 049a88c | 2017-01-12 17:49:37 +0530 | [diff] [blame] | 570 | |
| 571 | |
| 572 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 573 | @frappe.validate_and_sanitize_search_inputs |
suyashphadtare | 049a88c | 2017-01-12 17:49:37 +0530 | [diff] [blame] | 574 | def warehouse_query(doctype, txt, searchfield, start, page_len, filters): |
| 575 | # Should be used when item code is passed in filters. |
suyashphadtare | 750a067 | 2017-01-18 15:35:01 +0530 | [diff] [blame] | 576 | conditions, bin_conditions = [], [] |
| 577 | filter_dict = get_doctype_wise_filters(filters) |
| 578 | |
Rushabh Mehta | 7e506af | 2017-08-24 15:23:33 +0530 | [diff] [blame] | 579 | query = """select `tabWarehouse`.name, |
Diksha Jadhav | 182ee5e | 2020-08-18 00:35:04 +0530 | [diff] [blame] | 580 | CONCAT_WS(" : ", "Actual Qty", ifnull(round(`tabBin`.actual_qty, 2), 0 )) actual_qty |
| 581 | from `tabWarehouse` left join `tabBin` |
| 582 | on `tabBin`.warehouse = `tabWarehouse`.name {bin_conditions} |
suyashphadtare | 34ab136 | 2017-01-31 15:14:44 +0530 | [diff] [blame] | 583 | where |
Diksha Jadhav | 182ee5e | 2020-08-18 00:35:04 +0530 | [diff] [blame] | 584 | `tabWarehouse`.`{key}` like {txt} |
suyashphadtare | 34ab136 | 2017-01-31 15:14:44 +0530 | [diff] [blame] | 585 | {fcond} {mcond} |
Diksha Jadhav | 182ee5e | 2020-08-18 00:35:04 +0530 | [diff] [blame] | 586 | order by ifnull(`tabBin`.actual_qty, 0) desc |
suyashphadtare | 34ab136 | 2017-01-31 15:14:44 +0530 | [diff] [blame] | 587 | limit |
Rushabh Mehta | 7e506af | 2017-08-24 15:23:33 +0530 | [diff] [blame] | 588 | {start}, {page_len} |
suyashphadtare | 34ab136 | 2017-01-31 15:14:44 +0530 | [diff] [blame] | 589 | """.format( |
Diksha Jadhav | 182ee5e | 2020-08-18 00:35:04 +0530 | [diff] [blame] | 590 | bin_conditions=get_filters_cond(doctype, filter_dict.get("Bin"),bin_conditions, ignore_permissions=True), |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 591 | key=searchfield, |
suyashphadtare | 34ab136 | 2017-01-31 15:14:44 +0530 | [diff] [blame] | 592 | fcond=get_filters_cond(doctype, filter_dict.get("Warehouse"), conditions), |
Rushabh Mehta | 7e506af | 2017-08-24 15:23:33 +0530 | [diff] [blame] | 593 | mcond=get_match_cond(doctype), |
| 594 | start=start, |
| 595 | page_len=page_len, |
| 596 | txt=frappe.db.escape('%{0}%'.format(txt)) |
| 597 | ) |
| 598 | |
| 599 | return frappe.db.sql(query) |
suyashphadtare | 750a067 | 2017-01-18 15:35:01 +0530 | [diff] [blame] | 600 | |
| 601 | |
| 602 | def get_doctype_wise_filters(filters): |
| 603 | # Helper function to seperate filters doctype_wise |
| 604 | filter_dict = defaultdict(list) |
| 605 | for row in filters: |
| 606 | filter_dict[row[0]].append(row) |
| 607 | return filter_dict |
tundebabzy | 2a4fefc | 2017-11-29 06:23:09 +0100 | [diff] [blame] | 608 | |
| 609 | |
| 610 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 611 | @frappe.validate_and_sanitize_search_inputs |
tundebabzy | 2a4fefc | 2017-11-29 06:23:09 +0100 | [diff] [blame] | 612 | def get_batch_numbers(doctype, txt, searchfield, start, page_len, filters): |
rohitwaghchaure | 9fbed56 | 2018-01-12 16:22:33 +0530 | [diff] [blame] | 613 | query = """select batch_id from `tabBatch` |
Doridel Cahanap | 59e4c32 | 2018-08-06 17:15:18 +0800 | [diff] [blame] | 614 | where disabled = 0 |
| 615 | and (expiry_date >= CURDATE() or expiry_date IS NULL) |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 616 | and name like {txt}""".format(txt = frappe.db.escape('%{0}%'.format(txt))) |
tundebabzy | 2a4fefc | 2017-11-29 06:23:09 +0100 | [diff] [blame] | 617 | |
rohitwaghchaure | 9fbed56 | 2018-01-12 16:22:33 +0530 | [diff] [blame] | 618 | if filters and filters.get('item'): |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 619 | query += " and item = {item}".format(item = frappe.db.escape(filters.get('item'))) |
tundebabzy | 2a4fefc | 2017-11-29 06:23:09 +0100 | [diff] [blame] | 620 | |
Sachin Mane | 64f48db | 2018-01-08 17:57:32 +0530 | [diff] [blame] | 621 | return frappe.db.sql(query, filters) |
Rohit Waghchaure | 3cf2436 | 2019-06-02 16:03:05 +0530 | [diff] [blame] | 622 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 623 | |
Rohit Waghchaure | 3cf2436 | 2019-06-02 16:03:05 +0530 | [diff] [blame] | 624 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 625 | @frappe.validate_and_sanitize_search_inputs |
Rohit Waghchaure | 3cf2436 | 2019-06-02 16:03:05 +0530 | [diff] [blame] | 626 | def item_manufacturer_query(doctype, txt, searchfield, start, page_len, filters): |
Marica | bac4b93 | 2019-09-16 19:44:28 +0530 | [diff] [blame] | 627 | item_filters = [ |
| 628 | ['manufacturer', 'like', '%' + txt + '%'], |
| 629 | ['item_code', '=', filters.get("item_code")] |
| 630 | ] |
Rohit Waghchaure | 3cf2436 | 2019-06-02 16:03:05 +0530 | [diff] [blame] | 631 | |
Marica | bac4b93 | 2019-09-16 19:44:28 +0530 | [diff] [blame] | 632 | item_manufacturers = frappe.get_all( |
| 633 | "Item Manufacturer", |
| 634 | fields=["manufacturer", "manufacturer_part_no"], |
| 635 | filters=item_filters, |
Rohit Waghchaure | 3cf2436 | 2019-06-02 16:03:05 +0530 | [diff] [blame] | 636 | limit_start=start, |
| 637 | limit_page_length=page_len, |
| 638 | as_list=1 |
| 639 | ) |
Marica | bac4b93 | 2019-09-16 19:44:28 +0530 | [diff] [blame] | 640 | return item_manufacturers |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 641 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 642 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 643 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 644 | @frappe.validate_and_sanitize_search_inputs |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 645 | def get_purchase_receipts(doctype, txt, searchfield, start, page_len, filters): |
| 646 | query = """ |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 647 | select pr.name |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 648 | from `tabPurchase Receipt` pr, `tabPurchase Receipt Item` pritem |
| 649 | where pr.docstatus = 1 and pritem.parent = pr.name |
| 650 | and pr.name like {txt}""".format(txt = frappe.db.escape('%{0}%'.format(txt))) |
| 651 | |
| 652 | if filters and filters.get('item_code'): |
| 653 | query += " and pritem.item_code = {item_code}".format(item_code = frappe.db.escape(filters.get('item_code'))) |
| 654 | |
| 655 | return frappe.db.sql(query, filters) |
| 656 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 657 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 658 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 659 | @frappe.validate_and_sanitize_search_inputs |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 660 | def get_purchase_invoices(doctype, txt, searchfield, start, page_len, filters): |
| 661 | query = """ |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 662 | select pi.name |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 663 | from `tabPurchase Invoice` pi, `tabPurchase Invoice Item` piitem |
| 664 | where pi.docstatus = 1 and piitem.parent = pi.name |
| 665 | and pi.name like {txt}""".format(txt = frappe.db.escape('%{0}%'.format(txt))) |
| 666 | |
| 667 | if filters and filters.get('item_code'): |
| 668 | query += " and piitem.item_code = {item_code}".format(item_code = frappe.db.escape(filters.get('item_code'))) |
| 669 | |
| 670 | return frappe.db.sql(query, filters) |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 671 | |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 672 | |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 673 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 674 | @frappe.validate_and_sanitize_search_inputs |
Rucha Mahabal | 20e5315 | 2021-01-18 14:56:55 +0530 | [diff] [blame] | 675 | def get_healthcare_service_units(doctype, txt, searchfield, start, page_len, filters): |
| 676 | query = """ |
| 677 | select name |
| 678 | from `tabHealthcare Service Unit` |
| 679 | where |
| 680 | is_group = 0 |
| 681 | and company = {company} |
| 682 | and name like {txt}""".format( |
| 683 | company = frappe.db.escape(filters.get('company')), txt = frappe.db.escape('%{0}%'.format(txt))) |
| 684 | |
| 685 | if filters and filters.get('inpatient_record'): |
| 686 | from erpnext.healthcare.doctype.inpatient_medication_entry.inpatient_medication_entry import get_current_healthcare_service_unit |
| 687 | service_unit = get_current_healthcare_service_unit(filters.get('inpatient_record')) |
| 688 | |
| 689 | # if the patient is admitted, then appointments should be allowed against the admission service unit, |
| 690 | # inspite of it being an Inpatient Occupancy service unit |
| 691 | if service_unit: |
| 692 | query += " and (allow_appointments = 1 or name = {service_unit})".format(service_unit = frappe.db.escape(service_unit)) |
| 693 | else: |
| 694 | query += " and allow_appointments = 1" |
| 695 | else: |
| 696 | query += " and allow_appointments = 1" |
| 697 | |
| 698 | return frappe.db.sql(query, filters) |
| 699 | |
| 700 | |
| 701 | @frappe.whitelist() |
| 702 | @frappe.validate_and_sanitize_search_inputs |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 703 | def get_tax_template(doctype, txt, searchfield, start, page_len, filters): |
| 704 | |
| 705 | item_doc = frappe.get_cached_doc('Item', filters.get('item_code')) |
| 706 | item_group = filters.get('item_group') |
| 707 | taxes = item_doc.taxes or [] |
| 708 | |
| 709 | while item_group: |
| 710 | item_group_doc = frappe.get_cached_doc('Item Group', item_group) |
| 711 | taxes += item_group_doc.taxes or [] |
| 712 | item_group = item_group_doc.parent_item_group |
| 713 | |
| 714 | if not taxes: |
| 715 | return frappe.db.sql(""" SELECT name FROM `tabItem Tax Template` """) |
| 716 | else: |
Marica | 0fcb05a | 2020-08-10 14:48:13 +0530 | [diff] [blame] | 717 | valid_from = filters.get('valid_from') |
| 718 | valid_from = valid_from[1] if isinstance(valid_from, list) else valid_from |
| 719 | |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 720 | args = { |
| 721 | 'item_code': filters.get('item_code'), |
Marica | 0fcb05a | 2020-08-10 14:48:13 +0530 | [diff] [blame] | 722 | 'posting_date': valid_from, |
mohammadahmad1990 | 41c0c9f | 2020-06-18 11:18:44 +0500 | [diff] [blame] | 723 | 'tax_category': filters.get('tax_category'), |
| 724 | 'company': filters.get('company') |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | taxes = _get_item_tax_template(args, taxes, for_validate=True) |
| 728 | return [(d,) for d in set(taxes)] |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 729 | |
| 730 | |
Ankush Menat | 7eac4a2 | 2021-04-19 10:33:39 +0530 | [diff] [blame] | 731 | def get_fields(doctype, fields=None): |
| 732 | if fields is None: |
| 733 | fields = [] |
Himanshu | d94a38e | 2020-05-18 14:26:26 +0530 | [diff] [blame] | 734 | meta = frappe.get_meta(doctype) |
| 735 | fields.extend(meta.get_search_fields()) |
| 736 | |
| 737 | if meta.title_field and not meta.title_field.strip() in fields: |
| 738 | fields.insert(1, meta.title_field.strip()) |
| 739 | |
| 740 | return unique(fields) |