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.
 
 
 
 
 
 

43 lines
1.2 KiB

  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. @webnotes.whitelist()
  6. def get_data(module, doctypes='[]'):
  7. doctypes = json.loads(doctypes)
  8. return {
  9. "reports": get_report_list(module),
  10. "item_count": get_count(doctypes)
  11. }
  12. def get_count(doctypes):
  13. count = {}
  14. for d in doctypes:
  15. count[d] = get_doctype_count_from_table(d)
  16. return count
  17. def get_doctype_count_from_table(doctype):
  18. try:
  19. count = webnotes.conn.sql("""select count(*) from `tab%s`""" % doctype)[0][0]
  20. except Exception, e:
  21. if e.args[0]==1146:
  22. count = None
  23. else:
  24. raise e
  25. return count
  26. def get_report_list(module):
  27. """return list on new style reports for modules"""
  28. return webnotes.conn.sql("""
  29. select distinct tabReport.name, tabReport.ref_doctype as doctype,
  30. if((tabReport.report_type='Query Report' or
  31. tabReport.report_type='Script Report'), 1, 0) as is_query_report
  32. from `tabReport`, `tabDocType`
  33. where tabDocType.module=%s
  34. and tabDocType.name = tabReport.ref_doctype
  35. and tabReport.docstatus in (0, NULL)
  36. and ifnull(tabReport.is_standard, "No")="No"
  37. and ifnull(tabReport.disabled,0) != 1
  38. order by tabReport.name""", module, as_dict=True)