feat: Standard accounts dashboard
This commit is contained in:
parent
58f02e7c10
commit
0defefda92
0
erpnext/accounts/accounts
Normal file
0
erpnext/accounts/accounts
Normal file
@ -6,7 +6,7 @@ import frappe, json
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import add_to_date, date_diff, getdate, nowdate, get_last_day, formatdate, get_link_to_form
|
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 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.desk.doctype.dashboard_chart.dashboard_chart import get_period_ending
|
||||||
|
|
||||||
from frappe.utils.nestedset import get_descendants_of
|
from frappe.utils.nestedset import get_descendants_of
|
||||||
|
153
erpnext/accounts/dashboard_fixtures.py
Normal file
153
erpnext/accounts/dashboard_fixtures.py
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
import json
|
||||||
|
from frappe.utils import nowdate, add_months
|
||||||
|
|
||||||
|
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_data():
|
||||||
|
return frappe._dict({
|
||||||
|
"dashboards": get_dashboards(),
|
||||||
|
"charts": get_charts()
|
||||||
|
})
|
||||||
|
|
||||||
|
def get_dashboards():
|
||||||
|
|
||||||
|
return [{
|
||||||
|
"name": "Accounts Dashboard",
|
||||||
|
"dashboard_name": "Accounts",
|
||||||
|
"doctype": "Dashboard",
|
||||||
|
"charts": [
|
||||||
|
{ "chart": "Profit and Loss" , "width": "Full"},
|
||||||
|
{ "chart": "Incoming Bills"},
|
||||||
|
{ "chart": "Outgoing Bills"},
|
||||||
|
{ "chart": "Accounts Receivable Ageing"},
|
||||||
|
{ "chart": "Accounts Payable Ageing"},
|
||||||
|
{ "chart": "Bank Balance", "width": "Full"},
|
||||||
|
]
|
||||||
|
}]
|
||||||
|
|
||||||
|
def get_charts():
|
||||||
|
company = frappe.get_doc("Company", get_company_for_dashboards())
|
||||||
|
bank_account = company.default_bank_account or get_account("Bank", company.name)
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"doctype": "Dashboard Charts",
|
||||||
|
"name": "Profit and Loss",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"report_name": "Profit and Loss Statement",
|
||||||
|
"filters_json": json.dumps({
|
||||||
|
"company": company.name,
|
||||||
|
"filter_based_on": "Date Range",
|
||||||
|
"period_start_date": add_months(nowdate(), -4),
|
||||||
|
"period_end_date": nowdate(),
|
||||||
|
"periodicity": "Monthly",
|
||||||
|
"include_default_book_entries": 1
|
||||||
|
}),
|
||||||
|
"type": "Bar",
|
||||||
|
'timeseries': 0,
|
||||||
|
"chart_type": "Report",
|
||||||
|
"chart_name": "Profit and Loss",
|
||||||
|
"is_custom": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Dashboard Chart",
|
||||||
|
"time_interval": "Monthly",
|
||||||
|
"name": "Incoming Bills",
|
||||||
|
"chart_name": "Incoming Bills (Purchase Invoice)",
|
||||||
|
"timespan": "Last Year",
|
||||||
|
"color": "#a83333",
|
||||||
|
"value_based_on": "base_grand_total",
|
||||||
|
"filters_json": json.dumps({}),
|
||||||
|
"chart_type": "Sum",
|
||||||
|
"timeseries": 1,
|
||||||
|
"based_on": "posting_date",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"document_type": "Purchase Invoice",
|
||||||
|
"type": "Bar",
|
||||||
|
"width": "Half"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Dashboard Chart",
|
||||||
|
"name": "Outgoing Bills",
|
||||||
|
"time_interval": "Monthly",
|
||||||
|
"chart_name": "Outgoing Bills (Sales Invoice)",
|
||||||
|
"timespan": "Last Year",
|
||||||
|
"color": "#7b933d",
|
||||||
|
"value_based_on": "base_grand_total",
|
||||||
|
"filters_json": json.dumps({}),
|
||||||
|
"chart_type": "Sum",
|
||||||
|
"timeseries": 1,
|
||||||
|
"based_on": "posting_date",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"document_type": "Sales Invoice",
|
||||||
|
"type": "Bar",
|
||||||
|
"width": "Half"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Dashboard Charts",
|
||||||
|
"name": "Accounts Receivable Ageing",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"report_name": "Accounts Receivable",
|
||||||
|
"filters_json": json.dumps({
|
||||||
|
"company": company.name,
|
||||||
|
"report_date": nowdate(),
|
||||||
|
"ageing_based_on": "Due Date",
|
||||||
|
"range1": 30,
|
||||||
|
"range2": 60,
|
||||||
|
"range3": 90,
|
||||||
|
"range4": 120
|
||||||
|
}),
|
||||||
|
"type": "Donut",
|
||||||
|
'timeseries': 0,
|
||||||
|
"chart_type": "Report",
|
||||||
|
"chart_name": "Accounts Receivable Ageing",
|
||||||
|
"is_custom": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Dashboard Charts",
|
||||||
|
"name": "Accounts Payable Ageing",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"report_name": "Accounts Payable",
|
||||||
|
"filters_json": json.dumps({
|
||||||
|
"company": company.name,
|
||||||
|
"report_date": nowdate(),
|
||||||
|
"ageing_based_on": "Due Date",
|
||||||
|
"range1": 30,
|
||||||
|
"range2": 60,
|
||||||
|
"range3": 90,
|
||||||
|
"range4": 120
|
||||||
|
}),
|
||||||
|
"type": "Donut",
|
||||||
|
'timeseries': 0,
|
||||||
|
"chart_type": "Report",
|
||||||
|
"chart_name": "Accounts Payable Ageing",
|
||||||
|
"is_custom": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Dashboard Charts",
|
||||||
|
"name": "Bank Balance",
|
||||||
|
"time_interval": "Quarterly",
|
||||||
|
"chart_name": "Bank Balance",
|
||||||
|
"timespan": "Last Year",
|
||||||
|
"filters_json": json.dumps({"company": company.name, "account": bank_account}),
|
||||||
|
"source": "Account Balance Timeline",
|
||||||
|
"chart_type": "Custom",
|
||||||
|
"timeseries": 1,
|
||||||
|
"owner": "Administrator",
|
||||||
|
"type": "Line",
|
||||||
|
"width": "Half"
|
||||||
|
},
|
||||||
|
|
||||||
|
]
|
@ -546,7 +546,7 @@ class ReceivablePayableReport(object):
|
|||||||
self.filters.range1, self.filters.range2, self.filters.range3, self.filters.range4 = 30, 60, 90, 120
|
self.filters.range1, self.filters.range2, self.filters.range3, self.filters.range4 = 30, 60, 90, 120
|
||||||
|
|
||||||
for i, days in enumerate([self.filters.range1, self.filters.range2, self.filters.range3, self.filters.range4]):
|
for i, days in enumerate([self.filters.range1, self.filters.range2, self.filters.range3, self.filters.range4]):
|
||||||
if row.age <= days:
|
if cint(row.age) <= cint(days):
|
||||||
index = i
|
index = i
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -3,21 +3,8 @@ from frappe import _
|
|||||||
import frappe
|
import frappe
|
||||||
import json
|
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_default_dashboards():
|
||||||
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 {
|
return {
|
||||||
"Dashboards": [
|
"Dashboards": [
|
||||||
@ -25,90 +12,11 @@ def get_default_dashboards():
|
|||||||
"doctype": "Dashboard",
|
"doctype": "Dashboard",
|
||||||
"dashboard_name": "Accounts",
|
"dashboard_name": "Accounts",
|
||||||
"charts": [
|
"charts": [
|
||||||
{ "chart": "Outgoing Bills (Sales Invoice)" },
|
|
||||||
{ "chart": "Incoming Bills (Purchase Invoice)" },
|
|
||||||
{ "chart": "Bank Balance" },
|
|
||||||
{ "chart": "Income" },
|
|
||||||
{ "chart": "Expenses" },
|
|
||||||
{ "chart": "Patient Appointments" }
|
{ "chart": "Patient Appointments" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Charts": [
|
"Charts": [
|
||||||
{
|
|
||||||
"doctype": "Dashboard Chart",
|
|
||||||
"time_interval": "Quarterly",
|
|
||||||
"chart_name": "Income",
|
|
||||||
"timespan": "Last Year",
|
|
||||||
"color": None,
|
|
||||||
"filters_json": json.dumps({"company": company.name, "account": income_account}),
|
|
||||||
"source": "Account Balance Timeline",
|
|
||||||
"chart_type": "Custom",
|
|
||||||
"timeseries": 1,
|
|
||||||
"owner": "Administrator",
|
|
||||||
"type": "Line",
|
|
||||||
"width": "Half"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Dashboard Chart",
|
|
||||||
"time_interval": "Quarterly",
|
|
||||||
"chart_name": "Expenses",
|
|
||||||
"timespan": "Last Year",
|
|
||||||
"color": None,
|
|
||||||
"filters_json": json.dumps({"company": company.name, "account": expense_account}),
|
|
||||||
"source": "Account Balance Timeline",
|
|
||||||
"chart_type": "Custom",
|
|
||||||
"timeseries": 1,
|
|
||||||
"owner": "Administrator",
|
|
||||||
"type": "Line",
|
|
||||||
"width": "Half"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Dashboard Chart",
|
|
||||||
"time_interval": "Quarterly",
|
|
||||||
"chart_name": "Bank Balance",
|
|
||||||
"timespan": "Last Year",
|
|
||||||
"color": "#ffb868",
|
|
||||||
"filters_json": json.dumps({"company": company.name, "account": bank_account}),
|
|
||||||
"source": "Account Balance Timeline",
|
|
||||||
"chart_type": "Custom",
|
|
||||||
"timeseries": 1,
|
|
||||||
"owner": "Administrator",
|
|
||||||
"type": "Line",
|
|
||||||
"width": "Half"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Dashboard Chart",
|
|
||||||
"time_interval": "Monthly",
|
|
||||||
"chart_name": "Incoming Bills (Purchase Invoice)",
|
|
||||||
"timespan": "Last Year",
|
|
||||||
"color": "#a83333",
|
|
||||||
"value_based_on": "base_grand_total",
|
|
||||||
"filters_json": json.dumps({}),
|
|
||||||
"chart_type": "Sum",
|
|
||||||
"timeseries": 1,
|
|
||||||
"based_on": "posting_date",
|
|
||||||
"owner": "Administrator",
|
|
||||||
"document_type": "Purchase Invoice",
|
|
||||||
"type": "Bar",
|
|
||||||
"width": "Half"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Dashboard Chart",
|
|
||||||
"time_interval": "Monthly",
|
|
||||||
"chart_name": "Outgoing Bills (Sales Invoice)",
|
|
||||||
"timespan": "Last Year",
|
|
||||||
"color": "#7b933d",
|
|
||||||
"value_based_on": "base_grand_total",
|
|
||||||
"filters_json": json.dumps({}),
|
|
||||||
"chart_type": "Sum",
|
|
||||||
"timeseries": 1,
|
|
||||||
"based_on": "posting_date",
|
|
||||||
"owner": "Administrator",
|
|
||||||
"document_type": "Sales Invoice",
|
|
||||||
"type": "Bar",
|
|
||||||
"width": "Half"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"time_interval": "Daily",
|
"time_interval": "Daily",
|
||||||
@ -126,8 +34,3 @@ def get_default_dashboards():
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_account(account_type, company):
|
|
||||||
accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company})
|
|
||||||
if accounts:
|
|
||||||
return accounts[0].name
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user