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