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 c3e2f7db12..5decccb486 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,7 +6,7 @@ import frappe, json from frappe import _ from frappe.utils import add_to_date, date_diff, getdate, nowdate, get_last_day, formatdate, get_link_to_form from erpnext.accounts.report.general_ledger.general_ledger import execute -from frappe.core.page.dashboard.dashboard import cache_source, get_from_date_from_timespan +from frappe.utils.dashboard import cache_source, get_from_date_from_timespan from frappe.desk.doctype.dashboard_chart.dashboard_chart import get_period_ending from frappe.utils.nestedset import get_descendants_of diff --git a/erpnext/setup/setup_wizard/data/dashboard_charts.py b/erpnext/accounts/dashboard_fixtures.py similarity index 66% rename from erpnext/setup/setup_wizard/data/dashboard_charts.py rename to erpnext/accounts/dashboard_fixtures.py index b182dfc103..30eb5e3115 100644 --- a/erpnext/setup/setup_wizard/data/dashboard_charts.py +++ b/erpnext/accounts/dashboard_fixtures.py @@ -1,43 +1,40 @@ -from __future__ import unicode_literals -from frappe import _ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + import frappe import json -def get_company_for_dashboards(): - company = frappe.defaults.get_defaults().company - if company: - return company - else: - company_list = frappe.get_list("Company") - if company_list: - return company_list[0].name - return None -def get_default_dashboards(): +def get_data(): + return frappe._dict({ + "dashboards": get_dashboards(), + "charts": get_charts(), + }) + +def get_dashboards(): + return [{ + "name": "Accounts", + "dashboard_name": "Accounts", + "charts": [ + { "chart": "Outgoing Bills (Sales Invoice)" }, + { "chart": "Incoming Bills (Purchase Invoice)" }, + { "chart": "Bank Balance" }, + { "chart": "Income" }, + { "chart": "Expenses" } + ] + }] + +def get_charts(): company = frappe.get_doc("Company", get_company_for_dashboards()) income_account = company.default_income_account or get_account("Income Account", company.name) expense_account = company.default_expense_account or get_account("Expense Account", company.name) bank_account = company.default_bank_account or get_account("Bank", company.name) - return { - "Dashboards": [ - { - "doctype": "Dashboard", - "dashboard_name": "Accounts", - "charts": [ - { "chart": "Outgoing Bills (Sales Invoice)" }, - { "chart": "Incoming Bills (Purchase Invoice)" }, - { "chart": "Bank Balance" }, - { "chart": "Income" }, - { "chart": "Expenses" }, - { "chart": "Patient Appointments" } - ] - } - ], - "Charts": [ + return [ { "doctype": "Dashboard Chart", "time_interval": "Quarterly", + "name": "Income", "chart_name": "Income", "timespan": "Last Year", "color": None, @@ -46,12 +43,12 @@ def get_default_dashboards(): "chart_type": "Custom", "timeseries": 1, "owner": "Administrator", - "type": "Line", - "width": "Half" + "type": "Line" }, { "doctype": "Dashboard Chart", "time_interval": "Quarterly", + "name": "Expenses", "chart_name": "Expenses", "timespan": "Last Year", "color": None, @@ -60,12 +57,12 @@ def get_default_dashboards(): "chart_type": "Custom", "timeseries": 1, "owner": "Administrator", - "type": "Line", - "width": "Half" + "type": "Line" }, { "doctype": "Dashboard Chart", "time_interval": "Quarterly", + "name": "Bank Balance", "chart_name": "Bank Balance", "timespan": "Last Year", "color": "#ffb868", @@ -74,12 +71,12 @@ def get_default_dashboards(): "chart_type": "Custom", "timeseries": 1, "owner": "Administrator", - "type": "Line", - "width": "Half" + "type": "Line" }, { "doctype": "Dashboard Chart", "time_interval": "Monthly", + "name": "Incoming Bills (Purchase Invoice)", "chart_name": "Incoming Bills (Purchase Invoice)", "timespan": "Last Year", "color": "#a83333", @@ -90,12 +87,12 @@ def get_default_dashboards(): "based_on": "posting_date", "owner": "Administrator", "document_type": "Purchase Invoice", - "type": "Bar", - "width": "Half" + "type": "Bar" }, { "doctype": "Dashboard Chart", "time_interval": "Monthly", + "name": "Outgoing Bills (Sales Invoice)", "chart_name": "Outgoing Bills (Sales Invoice)", "timespan": "Last Year", "color": "#7b933d", @@ -106,28 +103,17 @@ def get_default_dashboards(): "based_on": "posting_date", "owner": "Administrator", "document_type": "Sales Invoice", - "type": "Bar", - "width": "Half" - }, - { - "doctype": "Dashboard Chart", - "time_interval": "Daily", - "chart_name": "Patient Appointments", - "timespan": "Last Month", - "color": "#77ecca", - "filters_json": json.dumps({}), - "chart_type": "Count", - "timeseries": 1, - "based_on": "appointment_datetime", - "owner": "Administrator", - "document_type": "Patient Appointment", - "type": "Line", - "width": "Half" + "type": "Bar" } ] - } -def get_account(account_type, company): - accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company}) - if accounts: - return accounts[0].name + +def get_company_for_dashboards(): + company = frappe.defaults.get_defaults().company + if company: + return company + else: + company_list = frappe.get_list("Company") + if company_list: + return company_list[0].name + return None \ No newline at end of file diff --git a/erpnext/healthcare/dashboard_fixtures.py b/erpnext/healthcare/dashboard_fixtures.py new file mode 100644 index 0000000000..fc3d62f2d8 --- /dev/null +++ b/erpnext/healthcare/dashboard_fixtures.py @@ -0,0 +1,41 @@ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe +import json + + +def get_data(): + return frappe._dict({ + "dashboards": get_dashboards(), + "charts": get_charts(), + }) + +def get_dashboards(): + return [{ + "name": "Healthcare", + "dashboard_name": "Healthcare", + "charts": [ + { "chart": "Patient Appointments" } + ] + }] + +def get_charts(): + return [ + { + "doctype": "Dashboard Chart", + "time_interval": "Daily", + "name": "Patient Appointments", + "chart_name": "Patient Appointments", + "timespan": "Last Month", + "color": "#77ecca", + "filters_json": json.dumps({}), + "chart_type": "Count", + "timeseries": 1, + "based_on": "appointment_datetime", + "owner": "Administrator", + "document_type": "Patient Appointment", + "type": "Line", + "width": "Half" + } + ] diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 525593327e..3f90d36916 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -631,7 +631,6 @@ execute:frappe.reload_doc('desk', 'doctype', 'dashboard') execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart_source') execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart') execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart_field') -erpnext.patches.v12_0.add_default_dashboards # 2020-04-05 erpnext.patches.v12_0.remove_bank_remittance_custom_fields erpnext.patches.v12_0.generate_leave_ledger_entries execute:frappe.delete_doc_if_exists("Report", "Loan Repayment") diff --git a/erpnext/patches/v12_0/add_default_dashboards.py b/erpnext/patches/v12_0/add_default_dashboards.py deleted file mode 100644 index 2a91e1b932..0000000000 --- a/erpnext/patches/v12_0/add_default_dashboards.py +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright (c) 2019, Frappe and Contributors -# License: GNU General Public License v3. See license.txt - -import frappe -from erpnext.setup.setup_wizard.operations.install_fixtures import add_dashboards - -def execute(): - frappe.reload_doc("desk", "doctype", "number_card_link") - frappe.reload_doc("healthcare", "doctype", "patient_appointment") - add_dashboards() diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 3be6f44832..8bb0a0529d 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -485,8 +485,6 @@ def install_defaults(args=None): # bank account same as a CoA entry pass - add_dashboards() - # Now, with fixtures out of the way, onto concrete stuff records = [ @@ -504,27 +502,6 @@ def install_defaults(args=None): make_records(records) -def add_dashboards(): - from erpnext.setup.setup_wizard.data.dashboard_charts import get_company_for_dashboards - - if not get_company_for_dashboards(): - return - - from erpnext.setup.setup_wizard.data.dashboard_charts import get_default_dashboards - from frappe.modules.import_file import import_file_by_path - - dashboard_data = get_default_dashboards() - - # create account balance timeline before creating dashbaord charts - doctype = "dashboard_chart_source" - docname = "account_balance_timeline" - folder = os.path.dirname(frappe.get_module("erpnext.accounts").__file__) - doc_path = os.path.join(folder, doctype, docname, docname) + ".json" - import_file_by_path(doc_path, force=0, for_sync=True) - - make_records(dashboard_data["Charts"]) - make_records(dashboard_data["Dashboards"]) - def get_fy_details(fy_start_date, fy_end_date): start_year = getdate(fy_start_date).year