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.
 
 
 
 

189 rivejä
4.8 KiB

  1. # Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
  2. # License: GNU General Public License v3. See license.txt
  3. import json
  4. import frappe
  5. from frappe import _
  6. from frappe.utils import get_date_str, nowdate
  7. from erpnext.accounts.dashboard_fixtures import _get_fiscal_year
  8. from erpnext.buying.dashboard_fixtures import get_company_for_dashboards
  9. def get_data():
  10. fiscal_year = _get_fiscal_year(nowdate())
  11. if not fiscal_year:
  12. return frappe._dict()
  13. year_start_date = get_date_str(fiscal_year.get("year_start_date"))
  14. year_end_date = get_date_str(fiscal_year.get("year_end_date"))
  15. return frappe._dict(
  16. {
  17. "dashboards": get_dashboards(),
  18. "charts": get_charts(fiscal_year, year_start_date, year_end_date),
  19. "number_cards": get_number_cards(fiscal_year, year_start_date, year_end_date),
  20. }
  21. )
  22. def get_dashboards():
  23. return [
  24. {
  25. "name": "Asset",
  26. "dashboard_name": "Asset",
  27. "charts": [
  28. {"chart": "Asset Value Analytics", "width": "Full"},
  29. {"chart": "Category-wise Asset Value", "width": "Half"},
  30. {"chart": "Location-wise Asset Value", "width": "Half"},
  31. ],
  32. "cards": [
  33. {"card": "Total Assets"},
  34. {"card": "New Assets (This Year)"},
  35. {"card": "Asset Value"},
  36. ],
  37. }
  38. ]
  39. def get_charts(fiscal_year, year_start_date, year_end_date):
  40. company = get_company_for_dashboards()
  41. return [
  42. {
  43. "name": "Asset Value Analytics",
  44. "chart_name": _("Asset Value Analytics"),
  45. "chart_type": "Report",
  46. "report_name": "Fixed Asset Register",
  47. "is_custom": 1,
  48. "group_by_type": "Count",
  49. "number_of_groups": 0,
  50. "is_public": 0,
  51. "timespan": "Last Year",
  52. "time_interval": "Yearly",
  53. "timeseries": 0,
  54. "filters_json": json.dumps(
  55. {
  56. "company": company,
  57. "status": "In Location",
  58. "filter_based_on": "Fiscal Year",
  59. "from_fiscal_year": fiscal_year.get("name"),
  60. "to_fiscal_year": fiscal_year.get("name"),
  61. "period_start_date": year_start_date,
  62. "period_end_date": year_end_date,
  63. "date_based_on": "Purchase Date",
  64. "group_by": "--Select a group--",
  65. }
  66. ),
  67. "type": "Bar",
  68. "custom_options": json.dumps(
  69. {
  70. "type": "bar",
  71. "barOptions": {"stacked": 1},
  72. "axisOptions": {"shortenYAxisNumbers": 1},
  73. "tooltipOptions": {},
  74. }
  75. ),
  76. "doctype": "Dashboard Chart",
  77. "y_axis": [],
  78. },
  79. {
  80. "name": "Category-wise Asset Value",
  81. "chart_name": _("Category-wise Asset Value"),
  82. "chart_type": "Report",
  83. "report_name": "Fixed Asset Register",
  84. "x_field": "asset_category",
  85. "timeseries": 0,
  86. "filters_json": json.dumps(
  87. {
  88. "company": company,
  89. "status": "In Location",
  90. "group_by": "Asset Category",
  91. "is_existing_asset": 0,
  92. }
  93. ),
  94. "type": "Donut",
  95. "doctype": "Dashboard Chart",
  96. "y_axis": [
  97. {
  98. "parent": "Category-wise Asset Value",
  99. "parentfield": "y_axis",
  100. "parenttype": "Dashboard Chart",
  101. "y_field": "asset_value",
  102. "doctype": "Dashboard Chart Field",
  103. }
  104. ],
  105. "custom_options": json.dumps(
  106. {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}}
  107. ),
  108. },
  109. {
  110. "name": "Location-wise Asset Value",
  111. "chart_name": "Location-wise Asset Value",
  112. "chart_type": "Report",
  113. "report_name": "Fixed Asset Register",
  114. "x_field": "location",
  115. "timeseries": 0,
  116. "filters_json": json.dumps(
  117. {"company": company, "status": "In Location", "group_by": "Location", "is_existing_asset": 0}
  118. ),
  119. "type": "Donut",
  120. "doctype": "Dashboard Chart",
  121. "y_axis": [
  122. {
  123. "parent": "Location-wise Asset Value",
  124. "parentfield": "y_axis",
  125. "parenttype": "Dashboard Chart",
  126. "y_field": "asset_value",
  127. "doctype": "Dashboard Chart Field",
  128. }
  129. ],
  130. "custom_options": json.dumps(
  131. {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}}
  132. ),
  133. },
  134. ]
  135. def get_number_cards(fiscal_year, year_start_date, year_end_date):
  136. return [
  137. {
  138. "name": "Total Assets",
  139. "label": _("Total Assets"),
  140. "function": "Count",
  141. "document_type": "Asset",
  142. "is_public": 1,
  143. "show_percentage_stats": 1,
  144. "stats_time_interval": "Monthly",
  145. "filters_json": "[]",
  146. "doctype": "Number Card",
  147. },
  148. {
  149. "name": "New Assets (This Year)",
  150. "label": _("New Assets (This Year)"),
  151. "function": "Count",
  152. "document_type": "Asset",
  153. "is_public": 1,
  154. "show_percentage_stats": 1,
  155. "stats_time_interval": "Monthly",
  156. "filters_json": json.dumps(
  157. [["Asset", "creation", "between", [year_start_date, year_end_date]]]
  158. ),
  159. "doctype": "Number Card",
  160. },
  161. {
  162. "name": "Asset Value",
  163. "label": _("Asset Value"),
  164. "function": "Sum",
  165. "aggregate_function_based_on": "value_after_depreciation",
  166. "document_type": "Asset",
  167. "is_public": 1,
  168. "show_percentage_stats": 1,
  169. "stats_time_interval": "Monthly",
  170. "filters_json": "[]",
  171. "doctype": "Number Card",
  172. },
  173. ]