You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

moduleview.py 1.3 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright 2013 Web Notes Technologies Pvt Ltd
  2. # License: MIT. See license.txt
  3. from __future__ import unicode_literals
  4. import webnotes, json
  5. from webnotes.widgets import reportview
  6. @webnotes.whitelist()
  7. def get_data(module, doctypes='[]'):
  8. doctypes = json.loads(doctypes)
  9. return {
  10. "reports": get_report_list(module),
  11. "item_count": get_count(doctypes)
  12. }
  13. def get_count(doctypes):
  14. count = {}
  15. for d in doctypes:
  16. try:
  17. count[d] = get_doctype_count_from_table(d)
  18. except webnotes.PermissionError, e:
  19. pass
  20. return count
  21. def get_doctype_count_from_table(doctype):
  22. try:
  23. count = reportview.execute(doctype, fields=["count(*)"], as_list=True)[0][0]
  24. except Exception, e:
  25. if e.args[0]==1146:
  26. count = None
  27. else:
  28. raise e
  29. return count
  30. def get_report_list(module):
  31. """return list on new style reports for modules"""
  32. return webnotes.conn.sql("""
  33. select distinct tabReport.name, tabReport.ref_doctype as doctype,
  34. if((tabReport.report_type='Query Report' or
  35. tabReport.report_type='Script Report'), 1, 0) as is_query_report
  36. from `tabReport`, `tabDocType`
  37. where tabDocType.module=%s
  38. and tabDocType.name = tabReport.ref_doctype
  39. and tabReport.docstatus in (0, NULL)
  40. and ifnull(tabReport.is_standard, "No")="No"
  41. and ifnull(tabReport.disabled,0) != 1
  42. order by tabReport.name""", module, as_dict=True)