From 953229fa470185fb2359fc588045c7f8d62ae109 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Tue, 8 Jan 2019 23:06:23 +0530 Subject: [PATCH 01/17] feat(dashboard): Create Accounting dashboard from General Ledger Report --- erpnext/accounts/dashboard.py | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 erpnext/accounts/dashboard.py diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py new file mode 100644 index 0000000000..a862ffaf67 --- /dev/null +++ b/erpnext/accounts/dashboard.py @@ -0,0 +1,39 @@ +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +from itertools import groupby +from operator import itemgetter +import frappe +from erpnext.accounts.report.general_ledger.general_ledger import execute + + +def get(): + filters = frappe._dict({ + "company": "Gadget Technologies Pvt. Ltd.", + "from_date": "2000-01-01", + "to_date": "2020-12-12", + "account": "Cash - GTPL", + "group_by": "Group by Voucher (Consolidated)" + }) + report_columns, report_results = execute(filters=filters) + + interesting_fields = ["posting_date", "balance"] + + columns = [column for column in report_columns if column["fieldname"] in interesting_fields] + + _results = [] + for row in report_results[1:-2]: + _results.append([row[key] for key in interesting_fields]) + + grouped_results = groupby(_results, key=itemgetter(0)) + + results = [list(values)[-1] for key, values in grouped_results] + + return { + "labels": [result[0] for result in results], + "datasets": [{ + "name": "Cash - GTPL", + "values": [result[1] for result in results] + }] + } From 88963744132726fc5c556b3720fe198cc72e190a Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 9 Jan 2019 11:18:17 +0530 Subject: [PATCH 02/17] feat(dashboard): Add timespan filter --- erpnext/accounts/dashboard.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index a862ffaf67..26a53dad46 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -5,13 +5,14 @@ from __future__ import unicode_literals from itertools import groupby from operator import itemgetter import frappe +from frappe.utils import add_to_date from erpnext.accounts.report.general_ledger.general_ledger import execute -def get(): +def get(filters=None): filters = frappe._dict({ "company": "Gadget Technologies Pvt. Ltd.", - "from_date": "2000-01-01", + "from_date": get_from_date_from_timespan(filters.get("timespan")), "to_date": "2020-12-12", "account": "Cash - GTPL", "group_by": "Group by Voucher (Consolidated)" @@ -37,3 +38,16 @@ def get(): "values": [result[1] for result in results] }] } + +def get_from_date_from_timespan(timespan): + days = months = years = 0 + if "Last Week" == timespan: + days = -7 + if "Last Month" == timespan: + months = -1 + elif "Last Quarter" == timespan: + months = -3 + elif "Last Year" == timespan: + years = -1 + return add_to_date(None, years=years, months=months, days=days, + as_string=True, as_datetime=True) From c888e52788ec37641f97f761d2052902db20582a Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 9 Jan 2019 12:10:37 +0530 Subject: [PATCH 03/17] feat(dashboard): Add missing dates --- erpnext/accounts/dashboard.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index 26a53dad46..df152f0eaf 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals from itertools import groupby from operator import itemgetter import frappe -from frappe.utils import add_to_date +from frappe.utils import add_to_date, date_diff, getdate, nowdate from erpnext.accounts.report.general_ledger.general_ledger import execute @@ -31,6 +31,8 @@ def get(filters=None): results = [list(values)[-1] for key, values in grouped_results] + results = add_missing_dates(results, from_date, to_date) + return { "labels": [result[0] for result in results], "datasets": [{ @@ -51,3 +53,17 @@ def get_from_date_from_timespan(timespan): years = -1 return add_to_date(None, years=years, months=months, days=days, as_string=True, as_datetime=True) + +def add_missing_dates(incomplete_results, from_date, to_date): + dates = [r[0] for r in incomplete_results] + day_count = date_diff(to_date, from_date) + + results_dict = dict(incomplete_results) + last_date, last_balance = incomplete_results[0] + results = [] + for date in (add_to_date(getdate(from_date), days=n) for n in range(day_count + 1)): + if date in results_dict: + last_date = date + last_balance = results_dict[date] + results.append([date, last_balance]) + return results From 6cadf77073879f1b98c50f2e913e1e4c4e327824 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 9 Jan 2019 12:50:50 +0530 Subject: [PATCH 04/17] feat(dashboard): Add Time Grain filter --- erpnext/accounts/dashboard.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index df152f0eaf..b9cb22e3f4 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -9,11 +9,16 @@ from frappe.utils import add_to_date, date_diff, getdate, nowdate from erpnext.accounts.report.general_ledger.general_ledger import execute -def get(filters=None): +def get(filters= None): + print(filters) + timespan = filters.get("timespan") + timegrain = filters.get("timegrain") + from_date = get_from_date_from_timespan(timespan) + to_date = nowdate() filters = frappe._dict({ "company": "Gadget Technologies Pvt. Ltd.", - "from_date": get_from_date_from_timespan(filters.get("timespan")), - "to_date": "2020-12-12", + "from_date": from_date, + "to_date": to_date, "account": "Cash - GTPL", "group_by": "Group by Voucher (Consolidated)" }) @@ -33,6 +38,8 @@ def get(filters=None): results = add_missing_dates(results, from_date, to_date) + results = granulate_results(results, from_date, to_date, timegrain) + return { "labels": [result[0] for result in results], "datasets": [{ @@ -67,3 +74,23 @@ def add_missing_dates(incomplete_results, from_date, to_date): last_balance = results_dict[date] results.append([date, last_balance]) return results + +def get_dates_from_timegrain(from_date, to_date, timegrain): + days = months = years = 0 + if "Daily" == timegrain: + days = 1 + elif "Weekly" == timegrain: + days = 7 + elif "Monthly" == timegrain: + months = 1 + elif "Quarterly" == timegrain: + months = 3 + + dates = [from_date] + while dates[-1] <= to_date: + dates.append(add_to_date(dates[-1], years=years, months=months, days=days)) + return dates + +def granulate_results(incomplete_results, from_date, to_date, timegrain): + dates = set(get_dates_from_timegrain(getdate(from_date), getdate(to_date), timegrain)) + return list(filter(lambda x: x[0] in dates,incomplete_results)) From 5911e100adcf88788a010b5393c6bc93d44e138c Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 9 Jan 2019 13:09:31 +0530 Subject: [PATCH 05/17] fix(dashboard): Consider opening balance --- erpnext/accounts/dashboard.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index b9cb22e3f4..b6ac4de9b7 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -32,6 +32,8 @@ def get(filters= None): for row in report_results[1:-2]: _results.append([row[key] for key in interesting_fields]) + _results = add_opening_balance(from_date, _results, report_results[0]) + grouped_results = groupby(_results, key=itemgetter(0)) results = [list(values)[-1] for key, values in grouped_results] @@ -61,6 +63,12 @@ def get_from_date_from_timespan(timespan): return add_to_date(None, years=years, months=months, days=days, as_string=True, as_datetime=True) + +def add_opening_balance(from_date, _results, opening): + if not _results or (_results[0][0] != getdate(from_date)): + _results.insert(0, [from_date, opening.balance]) + return _results + def add_missing_dates(incomplete_results, from_date, to_date): dates = [r[0] for r in incomplete_results] day_count = date_diff(to_date, from_date) From 3b593e44c60c7404663c703658f363573202c14d Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Thu, 10 Jan 2019 12:22:00 +0530 Subject: [PATCH 06/17] feat(dashboard): Set account from filters --- erpnext/accounts/dashboard.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index b6ac4de9b7..5d3984e134 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -13,13 +13,14 @@ def get(filters= None): print(filters) timespan = filters.get("timespan") timegrain = filters.get("timegrain") + account = filters.get("account") from_date = get_from_date_from_timespan(timespan) to_date = nowdate() filters = frappe._dict({ "company": "Gadget Technologies Pvt. Ltd.", "from_date": from_date, "to_date": to_date, - "account": "Cash - GTPL", + "account": account, "group_by": "Group by Voucher (Consolidated)" }) report_columns, report_results = execute(filters=filters) @@ -45,7 +46,7 @@ def get(filters= None): return { "labels": [result[0] for result in results], "datasets": [{ - "name": "Cash - GTPL", + "name": account, "values": [result[1] for result in results] }] } From 4b171ddebb2257e9dfb08438a8599869ee2dc063 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Tue, 15 Jan 2019 14:36:23 +0530 Subject: [PATCH 07/17] feat(dashboard): Remove hardcoded company filter --- erpnext/accounts/dashboard.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index 5d3984e134..2405d790de 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -14,10 +14,12 @@ def get(filters= None): timespan = filters.get("timespan") timegrain = filters.get("timegrain") account = filters.get("account") + company = filters.get("company") + from_date = get_from_date_from_timespan(timespan) to_date = nowdate() filters = frappe._dict({ - "company": "Gadget Technologies Pvt. Ltd.", + "company": company, "from_date": from_date, "to_date": to_date, "account": account, From 15c0cfff0f3bc2e0c2f53671747bb2018b2985f3 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Tue, 15 Jan 2019 14:37:50 +0530 Subject: [PATCH 08/17] refactor(dashboard): Convert indentation to tabs --- erpnext/accounts/dashboard.py | 148 +++++++++++++++++----------------- 1 file changed, 72 insertions(+), 76 deletions(-) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index 2405d790de..c9177ba4e8 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -10,98 +10,94 @@ from erpnext.accounts.report.general_ledger.general_ledger import execute def get(filters= None): - print(filters) - timespan = filters.get("timespan") - timegrain = filters.get("timegrain") - account = filters.get("account") - company = filters.get("company") + print(filters) + timespan = filters.get("timespan") + timegrain = filters.get("timegrain") + account = filters.get("account") + company = filters.get("company") - from_date = get_from_date_from_timespan(timespan) - to_date = nowdate() - filters = frappe._dict({ - "company": company, - "from_date": from_date, - "to_date": to_date, - "account": account, - "group_by": "Group by Voucher (Consolidated)" - }) - report_columns, report_results = execute(filters=filters) + from_date = get_from_date_from_timespan(timespan) + to_date = nowdate() + filters = frappe._dict({ + "company": company, + "from_date": from_date, + "to_date": to_date, + "account": account, + "group_by": "Group by Voucher (Consolidated)" + }) + report_columns, report_results = execute(filters=filters) - interesting_fields = ["posting_date", "balance"] + interesting_fields = ["posting_date", "balance"] - columns = [column for column in report_columns if column["fieldname"] in interesting_fields] + columns = [column for column in report_columns if column["fieldname"] in interesting_fields] - _results = [] - for row in report_results[1:-2]: - _results.append([row[key] for key in interesting_fields]) + _results = [] + for row in report_results[1:-2]: + _results.append([row[key] for key in interesting_fields]) - _results = add_opening_balance(from_date, _results, report_results[0]) + _results = add_opening_balance(from_date, _results, report_results[0]) + grouped_results = groupby(_results, key=itemgetter(0)) + results = [list(values)[-1] for key, values in grouped_results] + results = add_missing_dates(results, from_date, to_date) + results = granulate_results(results, from_date, to_date, timegrain) - grouped_results = groupby(_results, key=itemgetter(0)) - - results = [list(values)[-1] for key, values in grouped_results] - - results = add_missing_dates(results, from_date, to_date) - - results = granulate_results(results, from_date, to_date, timegrain) - - return { - "labels": [result[0] for result in results], - "datasets": [{ - "name": account, - "values": [result[1] for result in results] - }] - } + return { + "labels": [result[0] for result in results], + "datasets": [{ + "name": account, + "values": [result[1] for result in results] + }] + } def get_from_date_from_timespan(timespan): - days = months = years = 0 - if "Last Week" == timespan: - days = -7 - if "Last Month" == timespan: - months = -1 - elif "Last Quarter" == timespan: - months = -3 - elif "Last Year" == timespan: - years = -1 - return add_to_date(None, years=years, months=months, days=days, - as_string=True, as_datetime=True) + days = months = years = 0 + if "Last Week" == timespan: + days = -7 + if "Last Month" == timespan: + months = -1 + elif "Last Quarter" == timespan: + months = -3 + elif "Last Year" == timespan: + years = -1 + return add_to_date(None, years=years, months=months, days=days, + as_string=True, as_datetime=True) def add_opening_balance(from_date, _results, opening): - if not _results or (_results[0][0] != getdate(from_date)): - _results.insert(0, [from_date, opening.balance]) - return _results + if not _results or (_results[0][0] != getdate(from_date)): + _results.insert(0, [from_date, opening.balance]) + return _results def add_missing_dates(incomplete_results, from_date, to_date): - dates = [r[0] for r in incomplete_results] - day_count = date_diff(to_date, from_date) + dates = [r[0] for r in incomplete_results] + day_count = date_diff(to_date, from_date) - results_dict = dict(incomplete_results) - last_date, last_balance = incomplete_results[0] - results = [] - for date in (add_to_date(getdate(from_date), days=n) for n in range(day_count + 1)): - if date in results_dict: - last_date = date - last_balance = results_dict[date] - results.append([date, last_balance]) - return results + results_dict = dict(incomplete_results) + last_date, last_balance = incomplete_results[0] + results = [] + for date in (add_to_date(getdate(from_date), days=n) for n in range(day_count + 1)): + if date in results_dict: + last_date = date + last_balance = results_dict[date] + results.append([date, last_balance]) + return results def get_dates_from_timegrain(from_date, to_date, timegrain): - days = months = years = 0 - if "Daily" == timegrain: - days = 1 - elif "Weekly" == timegrain: - days = 7 - elif "Monthly" == timegrain: - months = 1 - elif "Quarterly" == timegrain: - months = 3 + days = months = years = 0 + if "Daily" == timegrain: + days = 1 + elif "Weekly" == timegrain: + days = 7 + elif "Monthly" == timegrain: + months = 1 + elif "Quarterly" == timegrain: + months = 3 - dates = [from_date] - while dates[-1] <= to_date: - dates.append(add_to_date(dates[-1], years=years, months=months, days=days)) - return dates + dates = [from_date] + while dates[-1] <= to_date: + dates.append(add_to_date(dates[-1], years=years, months=months, days=days)) + return dates def granulate_results(incomplete_results, from_date, to_date, timegrain): - dates = set(get_dates_from_timegrain(getdate(from_date), getdate(to_date), timegrain)) - return list(filter(lambda x: x[0] in dates,incomplete_results)) + dates = set(get_dates_from_timegrain(getdate(from_date), getdate(to_date), timegrain)) + return list(filter(lambda x: x[0] in dates,incomplete_results)) From 2fa1d9caeda5b4d7acac4a961c2b0af99a36bfda Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 16 Jan 2019 19:39:27 +0530 Subject: [PATCH 09/17] fix(dashboard): Remove print statement --- erpnext/accounts/dashboard.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index c9177ba4e8..d06700ddb1 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -10,7 +10,6 @@ from erpnext.accounts.report.general_ledger.general_ledger import execute def get(filters= None): - print(filters) timespan = filters.get("timespan") timegrain = filters.get("timegrain") account = filters.get("account") From d85b0ae602bbe33407142fe8abb5fee19340dd1c Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Thu, 17 Jan 2019 13:26:58 +0530 Subject: [PATCH 10/17] fix(dashboard): Remove unused variables --- erpnext/accounts/dashboard.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard.py index d06700ddb1..925f99a229 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard.py @@ -24,12 +24,10 @@ def get(filters= None): "account": account, "group_by": "Group by Voucher (Consolidated)" }) - report_columns, report_results = execute(filters=filters) + report_results = execute(filters=filters)[1] interesting_fields = ["posting_date", "balance"] - columns = [column for column in report_columns if column["fieldname"] in interesting_fields] - _results = [] for row in report_results[1:-2]: _results.append([row[key] for key in interesting_fields]) @@ -68,15 +66,13 @@ def add_opening_balance(from_date, _results, opening): return _results def add_missing_dates(incomplete_results, from_date, to_date): - dates = [r[0] for r in incomplete_results] day_count = date_diff(to_date, from_date) results_dict = dict(incomplete_results) - last_date, last_balance = incomplete_results[0] + last_balance = incomplete_results[0][1] results = [] for date in (add_to_date(getdate(from_date), days=n) for n in range(day_count + 1)): if date in results_dict: - last_date = date last_balance = results_dict[date] results.append([date, last_balance]) return results From 09f2ed2e69e08125d09e1158e8a5d2c66ae59eb1 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 6 Feb 2019 09:43:10 +0530 Subject: [PATCH 11/17] refactor(dashboard): Move dashboard.py to account_balance_timeline.py --- erpnext/accounts/dashboard_chart_source/__init__.py | 0 .../account_balance_timeline/__init__.py | 0 .../account_balance_timeline/account_balance_timeline.py} | 6 ++++-- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 erpnext/accounts/dashboard_chart_source/__init__.py create mode 100644 erpnext/accounts/dashboard_chart_source/account_balance_timeline/__init__.py rename erpnext/accounts/{dashboard.py => dashboard_chart_source/account_balance_timeline/account_balance_timeline.py} (97%) diff --git a/erpnext/accounts/dashboard_chart_source/__init__.py b/erpnext/accounts/dashboard_chart_source/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/__init__.py b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/dashboard.py b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py similarity index 97% rename from erpnext/accounts/dashboard.py rename to erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py index 925f99a229..6ecf3609f0 100644 --- a/erpnext/accounts/dashboard.py +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py @@ -4,12 +4,14 @@ from __future__ import unicode_literals from itertools import groupby from operator import itemgetter +import json import frappe from frappe.utils import add_to_date, date_diff, getdate, nowdate from erpnext.accounts.report.general_ledger.general_ledger import execute - -def get(filters= None): +@frappe.whitelist() +def get(filters=None): + filters = json.loads(filters) timespan = filters.get("timespan") timegrain = filters.get("timegrain") account = filters.get("account") From 675c1d3a5ac2d53146264f74e6b4cebaffdaffd6 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 6 Feb 2019 09:47:13 +0530 Subject: [PATCH 12/17] refactor(dashboard): Move Soure settings to account_balance_timeline.js --- .../account_balance_timeline.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js new file mode 100644 index 0000000000..c9a046f557 --- /dev/null +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js @@ -0,0 +1,44 @@ +frappe.dashboard_chart_sources["Account Balance Timeline"] = { + method_path: "erpnext.accounts.dashboard_chart_source.account_balance_timeline.account_balance_timeline.get", + filters: [ + { + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1 + }, + { + fieldname: "account", + label: __("Account"), + fieldtype: "Link", + options: "Account", + reqd: 1 + }, + { + fieldname: "timespan", + label: __("Period"), + fieldtype: "Select", + options: [ + {value: "Last Year", label: __("Last Year")}, + {value: "Last Quarter", label: __("Last Quarter")}, + {value: "Last Month", label: __("Last Month")}, + {value: "Last Week", label: __("Last Week")} + ], + reqd: 1 + }, + { + fieldname: "timegrain", + label: __("Periodicity"), + fieldtype: "Select", + options: [ + {value: "Quarterly", label: __("Quarterly")}, + {value: "Monthly", label: __("Monthly")}, + {value: "Weekly", label: __("Weekly")}, + {value: "Daily", label: __("Daily")} + ], + reqd: 1 + }, + ] +}; \ No newline at end of file From 76158e6643f07f77292e966e49091f10756719b1 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 6 Feb 2019 09:47:46 +0530 Subject: [PATCH 13/17] feat(dashboard): Export chart source doc to JSON file --- .../account_balance_timeline.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.json diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.json b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.json new file mode 100644 index 0000000000..4512715efc --- /dev/null +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.json @@ -0,0 +1,12 @@ +{ + "creation": "2019-02-06 07:57:10.377718", + "docstatus": 0, + "doctype": "Dashboard Chart Source", + "idx": 0, + "modified": "2019-02-06 08:33:37.637060", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Account Balance Timeline", + "owner": "Administrator", + "source_name": "Account Balance Timeline" +} \ No newline at end of file From 1e0f9a28822e377b9bf331d43e9206ad433b37f7 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 6 Feb 2019 10:14:21 +0530 Subject: [PATCH 14/17] feat(dashboard): Use caching decorator for dashboard --- .../account_balance_timeline/account_balance_timeline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py index 6ecf3609f0..c2c2423805 100644 --- a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py @@ -6,12 +6,13 @@ from itertools import groupby from operator import itemgetter import json import frappe +from frappe.core.page.dashboard.dashboard import cache_source from frappe.utils import add_to_date, date_diff, getdate, nowdate from erpnext.accounts.report.general_ledger.general_ledger import execute @frappe.whitelist() +@cache_source def get(filters=None): - filters = json.loads(filters) timespan = filters.get("timespan") timegrain = filters.get("timegrain") account = filters.get("account") From 59fc039c77d45db18d80655ba3a9f4c2306b11eb Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 6 Feb 2019 13:08:51 +0530 Subject: [PATCH 15/17] style: Linting fixes --- .../account_balance_timeline.js | 84 +++++++++---------- .../account_balance_timeline.py | 1 - 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js index c9a046f557..3d0eacc06f 100644 --- a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js @@ -1,44 +1,44 @@ frappe.dashboard_chart_sources["Account Balance Timeline"] = { - method_path: "erpnext.accounts.dashboard_chart_source.account_balance_timeline.account_balance_timeline.get", - filters: [ - { - fieldname: "company", - label: __("Company"), - fieldtype: "Link", - options: "Company", - default: frappe.defaults.get_user_default("Company"), - reqd: 1 - }, - { - fieldname: "account", - label: __("Account"), - fieldtype: "Link", - options: "Account", - reqd: 1 - }, - { - fieldname: "timespan", - label: __("Period"), - fieldtype: "Select", - options: [ - {value: "Last Year", label: __("Last Year")}, - {value: "Last Quarter", label: __("Last Quarter")}, - {value: "Last Month", label: __("Last Month")}, - {value: "Last Week", label: __("Last Week")} - ], - reqd: 1 - }, - { - fieldname: "timegrain", - label: __("Periodicity"), - fieldtype: "Select", - options: [ - {value: "Quarterly", label: __("Quarterly")}, - {value: "Monthly", label: __("Monthly")}, - {value: "Weekly", label: __("Weekly")}, - {value: "Daily", label: __("Daily")} - ], - reqd: 1 - }, - ] + method_path: "erpnext.accounts.dashboard_chart_source.account_balance_timeline.account_balance_timeline.get", + filters: [ + { + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1 + }, + { + fieldname: "account", + label: __("Account"), + fieldtype: "Link", + options: "Account", + reqd: 1 + }, + { + fieldname: "timespan", + label: __("Period"), + fieldtype: "Select", + options: [ + {value: "Last Year", label: __("Last Year")}, + {value: "Last Quarter", label: __("Last Quarter")}, + {value: "Last Month", label: __("Last Month")}, + {value: "Last Week", label: __("Last Week")} + ], + reqd: 1 + }, + { + fieldname: "timegrain", + label: __("Periodicity"), + fieldtype: "Select", + options: [ + {value: "Quarterly", label: __("Quarterly")}, + {value: "Monthly", label: __("Monthly")}, + {value: "Weekly", label: __("Weekly")}, + {value: "Daily", label: __("Daily")} + ], + reqd: 1 + }, + ] }; \ No newline at end of file diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py index c2c2423805..f98a236388 100644 --- a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals from itertools import groupby from operator import itemgetter -import json import frappe from frappe.core.page.dashboard.dashboard import cache_source from frappe.utils import add_to_date, date_diff, getdate, nowdate From 3b75551739ea84e4e40011b244ebb8f2cebb8dbb Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Wed, 6 Feb 2019 21:39:25 +0530 Subject: [PATCH 16/17] feat(dashboard): Render Account Balance Timeline is a time series --- .../account_balance_timeline/account_balance_timeline.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js index 3d0eacc06f..eebd2dbd34 100644 --- a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js @@ -40,5 +40,6 @@ frappe.dashboard_chart_sources["Account Balance Timeline"] = { ], reqd: 1 }, - ] + ], + is_time_series: true }; \ No newline at end of file From 42640cb90829615367f6e3f3a69d4e06b175f8d5 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Mon, 18 Mar 2019 11:18:43 +0530 Subject: [PATCH 17/17] fix(dashboard): Add configuration to chart source --- .../account_balance_timeline/account_balance_timeline.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.json b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.json index 4512715efc..b7ea601564 100644 --- a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.json +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.json @@ -1,9 +1,10 @@ { + "config": "{\n \"method_path\": \"erpnext.accounts.dashboard_chart_source.account_balance_timeline.account_balance_timeline.get\",\n\t\"filters\": [\n\t\t{\n\t\t\t\"fieldname\": \"company\",\n\t\t\t\"label\": \"Company\",\n\t\t\t\"fieldtype\": \"Link\",\n\t\t\t\"options\": \"Company\",\n\t\t\t\"reqd\": 1\n\t\t},\n\t\t{\n\t\t\t\"fieldname\": \"account\",\n\t\t\t\"label\": \"Account\",\n\t\t\t\"fieldtype\": \"Link\",\n\t\t\t\"options\": \"Account\",\n\t\t\t\"reqd\": 1\n\t\t},\n\t\t{\n\t\t\t\"fieldname\": \"timespan\",\n\t\t\t\"label\": \"Period\",\n\t\t\t\"fieldtype\": \"Select\",\n\t\t\t\"options\": [\n\t\t\t\t{\"value\": \"Last Year\", \"label\": \"Last Year\"},\n\t\t\t\t{\"value\": \"Last Quarter\", \"label\": \"Last Quarter\"},\n\t\t\t\t{\"value\": \"Last Month\", \"label\": \"Last Month\"},\n\t\t\t\t{\"value\": \"Last Week\", \"label\": \"Last Week\"}\n\t\t\t],\n\t\t\t\"reqd\": 1\n\t\t},\n\t\t{\n\t\t\t\"fieldname\": \"timegrain\",\n\t\t\t\"label\": \"Periodicity\",\n\t\t\t\"fieldtype\": \"Select\",\n\t\t\t\"options\": [\n\t\t\t\t{\"value\": \"Quarterly\", \"label\": \"Quarterly\"},\n\t\t\t\t{\"value\": \"Monthly\", \"label\": \"Monthly\"},\n\t\t\t\t{\"value\": \"Weekly\", \"label\": \"Weekly\"},\n\t\t\t\t{\"value\": \"Daily\", \"label\": \"Daily\"}\n\t\t\t],\n\t\t\t\"reqd\": 1\n\t\t}\n\t],\n\t\"is_time_series\": true\n}\n", "creation": "2019-02-06 07:57:10.377718", "docstatus": 0, "doctype": "Dashboard Chart Source", "idx": 0, - "modified": "2019-02-06 08:33:37.637060", + "modified": "2019-03-15 16:14:26.505986", "modified_by": "Administrator", "module": "Accounts", "name": "Account Balance Timeline",