marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 1 | # Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | import frappe |
| 5 | import json |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 6 | from frappe import _ |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 7 | from frappe.utils import nowdate |
| 8 | from erpnext.accounts.utils import get_fiscal_year |
| 9 | |
| 10 | def get_data(): |
| 11 | return frappe._dict({ |
| 12 | "dashboards": get_dashboards(), |
| 13 | "charts": get_charts(), |
| 14 | "number_cards": get_number_cards(), |
| 15 | }) |
| 16 | |
| 17 | def get_company_for_dashboards(): |
| 18 | company = frappe.defaults.get_defaults().company |
| 19 | if company: |
| 20 | return company |
| 21 | else: |
| 22 | company_list = frappe.get_list("Company") |
| 23 | if company_list: |
| 24 | return company_list[0].name |
| 25 | return None |
| 26 | |
| 27 | company = frappe.get_doc("Company", get_company_for_dashboards()) |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 28 | fiscal_year = get_fiscal_year(nowdate(), as_dict=1) |
| 29 | fiscal_year_name = fiscal_year.get("name") |
| 30 | start_date = str(fiscal_year.get("year_start_date")) |
| 31 | end_date = str(fiscal_year.get("year_end_date")) |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 32 | |
| 33 | def get_dashboards(): |
| 34 | return [{ |
| 35 | "name": "Stock", |
| 36 | "dashboard_name": "Stock", |
| 37 | "charts": [ |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 38 | { "chart": "Warehouse wise Stock Value", "width": "Full"}, |
| 39 | { "chart": "Purchase Receipt Trends", "width": "Half"}, |
| 40 | { "chart": "Delivery Trends", "width": "Half"}, |
| 41 | { "chart": "Oldest Items", "width": "Half"}, |
| 42 | { "chart": "Item Shortage Summary", "width": "Half"} |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 43 | ], |
| 44 | "cards": [ |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 45 | { "card": "Total Active Items"}, |
| 46 | { "card": "Total Warehouses"}, |
| 47 | { "card": "Total Stock Value"} |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 48 | ] |
| 49 | }] |
| 50 | |
| 51 | def get_charts(): |
| 52 | return [ |
| 53 | { |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 54 | "doctype": "Dashboard Chart", |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 55 | "name": "Purchase Receipt Trends", |
| 56 | "time_interval": "Monthly", |
| 57 | "chart_name": _("Purchase Receipt Trends"), |
| 58 | "timespan": "Last Year", |
| 59 | "color": "#7b933d", |
| 60 | "value_based_on": "base_net_total", |
| 61 | "filters_json": json.dumps([["Purchase Receipt", "docstatus", "=", 1]]), |
| 62 | "chart_type": "Sum", |
| 63 | "timeseries": 1, |
| 64 | "based_on": "posting_date", |
| 65 | "owner": "Administrator", |
| 66 | "document_type": "Purchase Receipt", |
| 67 | "type": "Bar", |
| 68 | "width": "Half", |
| 69 | "is_public": 1 |
| 70 | }, |
| 71 | { |
| 72 | "doctype": "Dashboard Chart", |
| 73 | "name": "Delivery Trends", |
| 74 | "time_interval": "Monthly", |
| 75 | "chart_name": _("Delivery Trends"), |
| 76 | "timespan": "Last Year", |
| 77 | "color": "#7b933d", |
| 78 | "value_based_on": "base_net_total", |
| 79 | "filters_json": json.dumps([["Delivery Note", "docstatus", "=", 1]]), |
| 80 | "chart_type": "Sum", |
| 81 | "timeseries": 1, |
| 82 | "based_on": "posting_date", |
| 83 | "owner": "Administrator", |
| 84 | "document_type": "Delivery Note", |
| 85 | "type": "Bar", |
| 86 | "width": "Half", |
| 87 | "is_public": 1 |
| 88 | }, |
| 89 | { |
| 90 | "name": "Warehouse wise Stock Value", |
| 91 | "chart_name": _("Warehouse wise Stock Value"), |
| 92 | "chart_type": "Custom", |
| 93 | "doctype": "Dashboard Chart", |
| 94 | "filters_json": json.dumps({}), |
| 95 | "is_custom": 0, |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 96 | "is_public": 1, |
| 97 | "owner": "Administrator", |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 98 | "source": "Warehouse wise Stock Value", |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 99 | "type": "Bar" |
| 100 | }, |
| 101 | { |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 102 | "name": "Oldest Items", |
| 103 | "chart_name": _("Oldest Items"), |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 104 | "chart_type": "Report", |
| 105 | "custom_options": json.dumps({ |
| 106 | "colors": ["#5e64ff"] |
| 107 | }), |
| 108 | "doctype": "Dashboard Chart", |
| 109 | "filters_json": json.dumps({ |
| 110 | "company": company.name, |
| 111 | "to_date": nowdate(), |
| 112 | "show_warehouse_wise_stock": 0 |
| 113 | }), |
| 114 | "is_custom": 1, |
| 115 | "is_public": 1, |
| 116 | "owner": "Administrator", |
| 117 | "report_name": "Stock Ageing", |
| 118 | "type": "Bar" |
| 119 | }, |
| 120 | { |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 121 | "name": "Item Shortage Summary", |
| 122 | "chart_name": _("Item Shortage Summary"), |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 123 | "chart_type": "Report", |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 124 | "doctype": "Dashboard Chart", |
| 125 | "filters_json": json.dumps({ |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 126 | "company": company.name |
| 127 | }), |
| 128 | "is_custom": 1, |
| 129 | "is_public": 1, |
| 130 | "owner": "Administrator", |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 131 | "report_name": "Item Shortage Report", |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 132 | "type": "Bar" |
| 133 | } |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 134 | ] |
| 135 | |
| 136 | def get_number_cards(): |
| 137 | return [ |
| 138 | { |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 139 | "name": "Total Active Items", |
| 140 | "label": _("Total Active Items"), |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 141 | "function": "Count", |
| 142 | "doctype": "Number Card", |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 143 | "document_type": "Item", |
| 144 | "filters_json": json.dumps([["Item", "disabled", "=", 0]]), |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 145 | "is_public": 1, |
| 146 | "owner": "Administrator", |
| 147 | "show_percentage_stats": 1, |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 148 | "stats_time_interval": "Monthly" |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 149 | }, |
| 150 | { |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 151 | "name": "Total Warehouses", |
| 152 | "label": _("Total Warehouses"), |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 153 | "function": "Count", |
| 154 | "doctype": "Number Card", |
Nabin Hait | 8b686a5 | 2020-05-19 19:08:30 +0530 | [diff] [blame] | 155 | "document_type": "Warehouse", |
| 156 | "filters_json": json.dumps([["Warehouse", "disabled", "=", 0]]), |
| 157 | "is_public": 1, |
| 158 | "owner": "Administrator", |
| 159 | "show_percentage_stats": 1, |
| 160 | "stats_time_interval": "Monthly" |
| 161 | }, |
| 162 | { |
| 163 | "name": "Total Stock Value", |
| 164 | "label": _("Total Stock Value"), |
| 165 | "function": "Sum", |
| 166 | "aggregate_function_based_on": "stock_value", |
| 167 | "doctype": "Number Card", |
| 168 | "document_type": "Bin", |
| 169 | "filters_json": json.dumps([]), |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 170 | "is_public": 1, |
| 171 | "owner": "Administrator", |
| 172 | "show_percentage_stats": 1, |
| 173 | "stats_time_interval": "Daily" |
| 174 | } |
| 175 | ] |