Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | # ERPNext - web based ERP (http://erpnext.com) |
| 2 | # Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | # |
| 4 | # This program is free software: you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 17 | from __future__ import unicode_literals |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 18 | import webnotes |
Anand Doshi | f9a3c8f | 2012-12-28 19:42:49 +0530 | [diff] [blame] | 19 | from webnotes import _, msgprint |
| 20 | from webnotes.utils import cint, comma_or |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 21 | |
| 22 | @webnotes.whitelist() |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 23 | def get_sc_list(arg=None): |
Anand Doshi | cdba51c | 2012-10-04 18:11:29 +0530 | [diff] [blame] | 24 | """return list of reports for the given module module""" |
| 25 | limit_start = webnotes.form_dict.get("limit_start") |
| 26 | limit_page_length = webnotes.form_dict.get("limit_page_length") |
| 27 | module = webnotes.form_dict.get("module") |
| 28 | |
| 29 | webnotes.response['values'] = webnotes.conn.sql(""" |
| 30 | select distinct criteria_name, doc_type, parent_doc_type |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 31 | from `tabSearch Criteria` |
Anand Doshi | cdba51c | 2012-10-04 18:11:29 +0530 | [diff] [blame] | 32 | where module=%s |
| 33 | and docstatus in (0, NULL) |
| 34 | and ifnull(disabled, 0) = 0 |
| 35 | order by criteria_name |
| 36 | limit %s, %s""" % \ |
| 37 | ("%s", cint(limit_start), cint(limit_page_length)), (module,), as_dict=True) |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 38 | |
| 39 | @webnotes.whitelist() |
| 40 | def get_report_list(): |
| 41 | """return list on new style reports for modules""" |
Anand Doshi | cdba51c | 2012-10-04 18:11:29 +0530 | [diff] [blame] | 42 | limit_start = webnotes.form_dict.get("limit_start") |
| 43 | limit_page_length = webnotes.form_dict.get("limit_page_length") |
| 44 | module = webnotes.form_dict.get("module") |
| 45 | |
| 46 | webnotes.response['values'] = webnotes.conn.sql(""" |
| 47 | select distinct tabReport.name, tabReport.ref_doctype, |
| 48 | if(ifnull(tabReport.query, '')!='', 1, 0) as is_query_report |
Rushabh Mehta | 16aea34 | 2012-05-29 10:53:37 +0530 | [diff] [blame] | 49 | from `tabReport`, `tabDocType` |
Anand Doshi | cdba51c | 2012-10-04 18:11:29 +0530 | [diff] [blame] | 50 | where tabDocType.module=%s |
| 51 | and tabDocType.name = tabReport.ref_doctype |
| 52 | and tabReport.docstatus in (0, NULL) |
Rushabh Mehta | 8ebf1b8 | 2012-12-19 15:34:00 +0530 | [diff] [blame] | 53 | and ifnull(tabReport.disabled,0) != 1 |
Anand Doshi | cdba51c | 2012-10-04 18:11:29 +0530 | [diff] [blame] | 54 | order by tabReport.name |
| 55 | limit %s, %s""" % \ |
Anand Doshi | f9a3c8f | 2012-12-28 19:42:49 +0530 | [diff] [blame] | 56 | ("%s", cint(limit_start), cint(limit_page_length)), (module,), as_dict=True) |
| 57 | |
| 58 | def validate_status(status, options): |
| 59 | if status not in options: |
| 60 | msgprint(_("Status must be one of ") + comma_or(options), raise_exception=True) |
Nabin Hait | a76a068 | 2013-02-08 14:04:13 +0530 | [diff] [blame] | 61 | |
| 62 | def build_filter_conditions(filters): |
| 63 | conditions, filter_values = [], [] |
| 64 | for key in filters: |
| 65 | conditions.append('`' + key + '` = %s') |
| 66 | filter_values.append(filters[key]) |
| 67 | |
| 68 | conditions = conditions and " and " + " and ".join(conditions) or "" |
| 69 | return conditions, filter_values |