Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

73 wiersze
2.7 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. from __future__ import unicode_literals
  23. import webnotes
  24. import os, json
  25. from webnotes import _
  26. from webnotes.modules import scrub, get_module_path
  27. @webnotes.whitelist()
  28. def get_script(report_name):
  29. report = webnotes.doc("Report", report_name)
  30. script_path = os.path.join(get_module_path(webnotes.conn.get_value("DocType", report.ref_doctype, "module")),
  31. "report", scrub(report.name), scrub(report.name) + ".js")
  32. if os.path.exists(script_path):
  33. with open(script_path, "r") as script:
  34. return script.read()
  35. else:
  36. return "wn.query_reports['%s']={}" % report_name
  37. @webnotes.whitelist()
  38. def run(report_name, filters=None):
  39. report = webnotes.doc("Report", report_name)
  40. if not webnotes.has_permission(report.ref_doctype, "report"):
  41. webnotes.msgprint(_("Must have report permission to access this report."),
  42. raise_exception=True)
  43. if report.report_type=="Query Report":
  44. if not report.query:
  45. webnotes.msgprint(_("Must specify a Query to run"), raise_exception=True)
  46. if not report.query.lower().startswith("select"):
  47. webnotes.msgprint(_("Query must be a SELECT"), raise_exception=True)
  48. result = [list(t) for t in webnotes.conn.sql(report.query)]
  49. columns = [c[0] for c in webnotes.conn.get_description()]
  50. else:
  51. if filters:
  52. filters = json.loads(filters)
  53. method_name = scrub(webnotes.conn.get_value("DocType", report.ref_doctype, "module")) \
  54. + ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute"
  55. columns, result = webnotes.get_method(method_name)(filters or {})
  56. return {
  57. "result": result,
  58. "columns": columns
  59. }