Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

64 righe
2.3 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. """build query for doclistview and return results"""
  23. import webnotes, json
  24. @webnotes.whitelist()
  25. def get(arg=None):
  26. """
  27. build query
  28. gets doctype, subject, filters
  29. limit_start, limit_page_length
  30. """
  31. data = webnotes.form_dict
  32. filters = json.loads(data['filters'])
  33. fields = json.loads(data['fields'])
  34. tables = ['`tab' + data['doctype'] + '`']
  35. conditions = [tables[0] + '.docstatus < 2']
  36. joined = [tables[0]]
  37. # make conditions from filters
  38. for f in filters:
  39. tname = ('`tab' + f[0] + '`')
  40. if not tname in tables:
  41. tables.append(tname)
  42. conditions.append(tname + '.' + f[1] + " " + f[2] + " '" + f[3].replace("'", "\'") + "'")
  43. if not tname in joined:
  44. conditions.append(tname + '.parent = ' + tables[0] + '.name')
  45. joined.append(tname)
  46. data['tables'] = ', '.join(tables)
  47. data['conditions'] = ' and '.join(conditions)
  48. data['fields'] = ', '.join(fields)
  49. if not data.get('order_by'):
  50. data['order_by'] = tables[0] + '.modified desc'
  51. query = """select %(fields)s from %(tables)s where %(conditions)s
  52. order by %(order_by)s
  53. limit %(limit_start)s, %(limit_page_length)s""" % data
  54. return webnotes.conn.sql(query, as_dict=1, debug=1)