25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

moduleview.py 2.3 KiB

12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. open_count, conditions = get_open_count(doctypes)
  9. return {
  10. "search_criteria": get_sc_list(module),
  11. "reports": get_report_list(module),
  12. "item_count": get_count(doctypes),
  13. "open_count": open_count,
  14. "conditions": conditions
  15. }
  16. def get_count(doctypes):
  17. count = {}
  18. for d in doctypes:
  19. count[d] = get_doctype_count_from_table(d)
  20. return count
  21. def get_doctype_count_from_table(doctype):
  22. try:
  23. count = webnotes.conn.sql("""select count(*) from `tab%s`""" % doctype)[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_open_count(doctypes):
  31. count = {}
  32. conditions = {}
  33. try:
  34. from startup.open_count import queries
  35. for d in doctypes:
  36. if d in queries:
  37. condition = queries[d]
  38. key = condition.keys()[0]
  39. query = "select count(*) from `tab%s` where `%s`=%s and docstatus<2" % (d, key, '%s')
  40. count[d] = webnotes.conn.sql(query, condition[key])[0][0] or ""
  41. conditions[d] = condition
  42. except ImportError, e:
  43. pass
  44. return count, conditions
  45. def get_doctype_count(doctype):
  46. count = webnotes.conn.get_global("item_count:" + doctype)
  47. if count is None:
  48. count = get_doctype_count_from_table(doctype)
  49. webnotes.conn.set_global("item_count:" + doctype, count)
  50. return count
  51. def get_sc_list(module):
  52. """return list of reports for the given module module"""
  53. return webnotes.conn.sql("""
  54. select distinct criteria_name, doc_type as doctype, parent_doc_type as parent_doctype
  55. from `tabSearch Criteria`
  56. where module=%s
  57. and docstatus in (0, NULL)
  58. and ifnull(disabled, 0) = 0
  59. order by criteria_name""", module, as_dict=True)
  60. def get_report_list(module):
  61. """return list on new style reports for modules"""
  62. return webnotes.conn.sql("""
  63. select distinct tabReport.name, tabReport.ref_doctype as doctype,
  64. if(ifnull(tabReport.query, '')!='', 1, 0) as is_query_report
  65. from `tabReport`, `tabDocType`
  66. where tabDocType.module=%s
  67. and tabDocType.name = tabReport.ref_doctype
  68. and tabReport.docstatus in (0, NULL)
  69. and ifnull(tabReport.is_standard, "No")="No"
  70. and ifnull(tabReport.disabled,0) != 1
  71. order by tabReport.name""", module, as_dict=True)