Nabin Hait | a76a068 | 2013-02-08 14:04:13 +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 | |
| 17 | from __future__ import unicode_literals |
| 18 | import webnotes |
| 19 | |
| 20 | def get_customer_list(doctype, txt, searchfield, start, page_len, filters): |
| 21 | if webnotes.conn.get_default("cust_master_name") == "Customer Name": |
| 22 | fields = ["name", "customer_group", "territory"] |
| 23 | else: |
| 24 | fields = ["name", "customer_name", "customer_group", "territory"] |
| 25 | |
| 26 | return webnotes.conn.sql("""select %s from `tabCustomer` where docstatus < 2 |
| 27 | and (%s like %s or customer_name like %s) order by |
| 28 | case when name like %s then 0 else 1 end, |
| 29 | case when customer_name like %s then 0 else 1 end, |
| 30 | name, customer_name limit %s, %s""" % |
| 31 | (", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"), |
| 32 | ("%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, start, page_len)) |