mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 08:24:47 +00:00
fix: Onboarding and Dashboard for accounts module
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
import frappe
|
import frappe
|
||||||
import json
|
import json
|
||||||
from frappe.utils import nowdate, add_months
|
from frappe.utils import nowdate, add_months
|
||||||
|
from frappe import _
|
||||||
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
|
||||||
def get_company_for_dashboards():
|
def get_company_for_dashboards():
|
||||||
company = frappe.defaults.get_defaults().company
|
company = frappe.defaults.get_defaults().company
|
||||||
@@ -18,11 +20,11 @@ def get_company_for_dashboards():
|
|||||||
def get_data():
|
def get_data():
|
||||||
return frappe._dict({
|
return frappe._dict({
|
||||||
"dashboards": get_dashboards(),
|
"dashboards": get_dashboards(),
|
||||||
"charts": get_charts()
|
"charts": get_charts(),
|
||||||
|
"number_cards": get_number_cards()
|
||||||
})
|
})
|
||||||
|
|
||||||
def get_dashboards():
|
def get_dashboards():
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
"name": "Accounts Dashboard",
|
"name": "Accounts Dashboard",
|
||||||
"dashboard_name": "Accounts",
|
"dashboard_name": "Accounts",
|
||||||
@@ -33,13 +35,19 @@ def get_dashboards():
|
|||||||
{ "chart": "Outgoing Bills"},
|
{ "chart": "Outgoing Bills"},
|
||||||
{ "chart": "Accounts Receivable Ageing"},
|
{ "chart": "Accounts Receivable Ageing"},
|
||||||
{ "chart": "Accounts Payable Ageing"},
|
{ "chart": "Accounts Payable Ageing"},
|
||||||
|
{ "chart": "Budget Variance", "width": "Full"},
|
||||||
{ "chart": "Bank Balance", "width": "Full"},
|
{ "chart": "Bank Balance", "width": "Full"},
|
||||||
|
],
|
||||||
|
"cards": [
|
||||||
|
{"card": "Total Payment Received"}
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def get_charts():
|
def get_charts():
|
||||||
company = frappe.get_doc("Company", get_company_for_dashboards())
|
company = frappe.get_doc("Company", get_company_for_dashboards())
|
||||||
bank_account = company.default_bank_account or get_account("Bank", company.name)
|
bank_account = company.default_bank_account or get_account("Bank", company.name)
|
||||||
|
fiscal_year = get_fiscal_year(date=nowdate())
|
||||||
|
default_cost_center = company.cost_center
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -58,14 +66,14 @@ def get_charts():
|
|||||||
"type": "Bar",
|
"type": "Bar",
|
||||||
'timeseries': 0,
|
'timeseries': 0,
|
||||||
"chart_type": "Report",
|
"chart_type": "Report",
|
||||||
"chart_name": "Profit and Loss",
|
"chart_name": _("Profit and Loss"),
|
||||||
"is_custom": 1
|
"is_custom": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"time_interval": "Monthly",
|
"time_interval": "Monthly",
|
||||||
"name": "Incoming Bills",
|
"name": "Incoming Bills",
|
||||||
"chart_name": "Incoming Bills (Purchase Invoice)",
|
"chart_name": _("Incoming Bills (Purchase Invoice)"),
|
||||||
"timespan": "Last Year",
|
"timespan": "Last Year",
|
||||||
"color": "#a83333",
|
"color": "#a83333",
|
||||||
"value_based_on": "base_grand_total",
|
"value_based_on": "base_grand_total",
|
||||||
@@ -82,7 +90,7 @@ def get_charts():
|
|||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"name": "Outgoing Bills",
|
"name": "Outgoing Bills",
|
||||||
"time_interval": "Monthly",
|
"time_interval": "Monthly",
|
||||||
"chart_name": "Outgoing Bills (Sales Invoice)",
|
"chart_name": _("Outgoing Bills (Sales Invoice)"),
|
||||||
"timespan": "Last Year",
|
"timespan": "Last Year",
|
||||||
"color": "#7b933d",
|
"color": "#7b933d",
|
||||||
"value_based_on": "base_grand_total",
|
"value_based_on": "base_grand_total",
|
||||||
@@ -112,7 +120,7 @@ def get_charts():
|
|||||||
"type": "Donut",
|
"type": "Donut",
|
||||||
'timeseries': 0,
|
'timeseries': 0,
|
||||||
"chart_type": "Report",
|
"chart_type": "Report",
|
||||||
"chart_name": "Accounts Receivable Ageing",
|
"chart_name": _("Accounts Receivable Ageing"),
|
||||||
"is_custom": 1
|
"is_custom": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -128,11 +136,29 @@ def get_charts():
|
|||||||
"range2": 60,
|
"range2": 60,
|
||||||
"range3": 90,
|
"range3": 90,
|
||||||
"range4": 120
|
"range4": 120
|
||||||
}),
|
}),
|
||||||
"type": "Donut",
|
"type": "Donut",
|
||||||
'timeseries': 0,
|
'timeseries': 0,
|
||||||
"chart_type": "Report",
|
"chart_type": "Report",
|
||||||
"chart_name": "Accounts Payable Ageing",
|
"chart_name": _("Accounts Payable Ageing"),
|
||||||
|
"is_custom": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Dashboard Charts",
|
||||||
|
"name": "Budget Variance",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"report_name": "Budget Variance Report",
|
||||||
|
"filters_json": json.dumps({
|
||||||
|
"company": company.name,
|
||||||
|
"from_fiscal_year": fiscal_year[0],
|
||||||
|
"to_fiscal_year": fiscal_year[0],
|
||||||
|
"period": "Monthly",
|
||||||
|
"budget_against": "Cost Center"
|
||||||
|
}),
|
||||||
|
"type": "Bar",
|
||||||
|
"timeseries": 0,
|
||||||
|
"chart_type": "Report",
|
||||||
|
"chart_name": _("Budget Variance"),
|
||||||
"is_custom": 1
|
"is_custom": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -149,5 +175,21 @@ def get_charts():
|
|||||||
"type": "Line",
|
"type": "Line",
|
||||||
"width": "Half"
|
"width": "Half"
|
||||||
},
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_number_cards():
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"doctype": "Number Card",
|
||||||
|
"document_type": "Payment Entry",
|
||||||
|
"name": "Total Payment Received",
|
||||||
|
"filters_json": json.dumps([]),
|
||||||
|
"label": _("Total Payment Received"),
|
||||||
|
"function": "Sum",
|
||||||
|
"aggregate_function_based_on": "base_received_amount",
|
||||||
|
"is_public": 1,
|
||||||
|
"is_custom": 1,
|
||||||
|
"show_percentage_stats": 1,
|
||||||
|
"stats_time_interval": "Daily"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -82,12 +82,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"category": "Modules",
|
"category": "Modules",
|
||||||
"charts": [
|
"charts": [],
|
||||||
{
|
|
||||||
"chart_name": "Bank Balance",
|
|
||||||
"label": "Bank Balance"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"creation": "2020-03-02 15:41:59.515192",
|
"creation": "2020-03-02 15:41:59.515192",
|
||||||
"developer_mode_only": 0,
|
"developer_mode_only": 0,
|
||||||
"disable_user_customization": 0,
|
"disable_user_customization": 0,
|
||||||
@@ -97,10 +92,11 @@
|
|||||||
"idx": 0,
|
"idx": 0,
|
||||||
"is_standard": 1,
|
"is_standard": 1,
|
||||||
"label": "Accounting",
|
"label": "Accounting",
|
||||||
"modified": "2020-05-12 17:20:27.573449",
|
"modified": "2020-05-14 22:28:25.262409",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Accounting",
|
"name": "Accounting",
|
||||||
|
"onboarding": "Accounts",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"pin_to_bottom": 0,
|
"pin_to_bottom": 0,
|
||||||
"pin_to_top": 0,
|
"pin_to_top": 0,
|
||||||
@@ -120,6 +116,11 @@
|
|||||||
"link_to": "Purchase Invoice",
|
"link_to": "Purchase Invoice",
|
||||||
"type": "DocType"
|
"type": "DocType"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Accounts Dashboard",
|
||||||
|
"link_to": "Accounts Dashboard",
|
||||||
|
"type": "Dashboard"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Journal Entry",
|
"label": "Journal Entry",
|
||||||
"link_to": "Journal Entry",
|
"link_to": "Journal Entry",
|
||||||
@@ -140,11 +141,6 @@
|
|||||||
"link_to": "General Ledger",
|
"link_to": "General Ledger",
|
||||||
"type": "Report"
|
"type": "Report"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"label": "Profit and Loss Statement",
|
|
||||||
"link_to": "Profit and Loss Statement",
|
|
||||||
"type": "Report"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"label": "Trial Balance",
|
"label": "Trial Balance",
|
||||||
"link_to": "Trial Balance",
|
"link_to": "Trial Balance",
|
||||||
|
|||||||
51
erpnext/accounts/module_onboarding/accounts/accounts.json
Normal file
51
erpnext/accounts/module_onboarding/accounts/accounts.json
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"allow_roles": [
|
||||||
|
{
|
||||||
|
"role": "Accounts Manager"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Accounts User"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"creation": "2020-05-13 19:03:32.564049",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Module Onboarding",
|
||||||
|
"documentation_url": "https://docs.erpnext.com/docs/user/manual/en/accounts",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"modified": "2020-05-14 22:11:06.475938",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "Accounts",
|
||||||
|
"name": "Accounts",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"step": "Chart Of Accounts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": "Setup Taxes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": "Create a Product"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": "Create a Supplier"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": "Create Your First Purchase Invoice"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": "Create a Customer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": "Create Your First Sales Invoice"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": "Configure Account Settings"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"subtitle": "Accounts, invoices and taxation.",
|
||||||
|
"success_message": "The Accounts module is now set up!",
|
||||||
|
"title": "Let's Setup Your Accounts and Taxes.",
|
||||||
|
"user_can_dismiss": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"action": "Go to Page",
|
||||||
|
"creation": "2020-05-13 19:58:20.928127",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Onboarding Step",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"is_mandatory": 0,
|
||||||
|
"is_single": 0,
|
||||||
|
"is_skipped": 0,
|
||||||
|
"modified": "2020-05-14 17:40:28.410447",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Chart Of Accounts",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"path": "Tree/Account",
|
||||||
|
"reference_document": "Account",
|
||||||
|
"show_full_form": 0,
|
||||||
|
"title": "Review Chart Of Accounts",
|
||||||
|
"validate_action": 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"action": "Create Entry",
|
||||||
|
"creation": "2020-05-14 17:53:00.876946",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Onboarding Step",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"is_mandatory": 0,
|
||||||
|
"is_single": 1,
|
||||||
|
"is_skipped": 0,
|
||||||
|
"modified": "2020-05-14 18:06:25.212923",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Configure Account Settings",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"reference_document": "Accounts Settings",
|
||||||
|
"show_full_form": 1,
|
||||||
|
"title": "Configure Account Settings",
|
||||||
|
"validate_action": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"action": "Create Entry",
|
||||||
|
"creation": "2020-05-14 17:46:41.831517",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Onboarding Step",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"is_mandatory": 0,
|
||||||
|
"is_single": 0,
|
||||||
|
"is_skipped": 0,
|
||||||
|
"modified": "2020-05-14 17:46:41.831517",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Create a Customer",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"reference_document": "Customer",
|
||||||
|
"show_full_form": 0,
|
||||||
|
"title": "Create a Customer",
|
||||||
|
"validate_action": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"action": "Create Entry",
|
||||||
|
"creation": "2020-05-14 17:45:28.554605",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Onboarding Step",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"is_mandatory": 0,
|
||||||
|
"is_single": 0,
|
||||||
|
"is_skipped": 0,
|
||||||
|
"modified": "2020-05-14 17:45:28.554605",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Create a Product",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"reference_document": "Item",
|
||||||
|
"show_full_form": 0,
|
||||||
|
"title": "Create a Product",
|
||||||
|
"validate_action": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"action": "Create Entry",
|
||||||
|
"creation": "2020-05-14 22:09:10.043554",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Onboarding Step",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"is_mandatory": 0,
|
||||||
|
"is_single": 0,
|
||||||
|
"is_skipped": 0,
|
||||||
|
"modified": "2020-05-14 22:09:10.043554",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Create a Supplier",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"reference_document": "Supplier",
|
||||||
|
"show_full_form": 0,
|
||||||
|
"title": "Create a Supplier",
|
||||||
|
"validate_action": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"action": "Create Entry",
|
||||||
|
"creation": "2020-05-14 22:10:07.049704",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Onboarding Step",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"is_mandatory": 0,
|
||||||
|
"is_single": 0,
|
||||||
|
"is_skipped": 0,
|
||||||
|
"modified": "2020-05-14 22:10:07.049704",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Create Your First Purchase Invoice",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"reference_document": "Purchase Invoice",
|
||||||
|
"show_full_form": 1,
|
||||||
|
"title": "Create Your First Purchase Invoice ",
|
||||||
|
"validate_action": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"action": "Create Entry",
|
||||||
|
"creation": "2020-05-14 17:48:21.019019",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Onboarding Step",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"is_mandatory": 0,
|
||||||
|
"is_single": 0,
|
||||||
|
"is_skipped": 0,
|
||||||
|
"modified": "2020-05-14 17:48:21.019019",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Create Your First Sales Invoice",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"reference_document": "Sales Invoice",
|
||||||
|
"show_full_form": 1,
|
||||||
|
"title": "Create Your First Sales Invoice ",
|
||||||
|
"validate_action": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"action": "Create Entry",
|
||||||
|
"creation": "2020-05-13 19:29:43.844463",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Onboarding Step",
|
||||||
|
"idx": 0,
|
||||||
|
"is_complete": 0,
|
||||||
|
"is_mandatory": 0,
|
||||||
|
"is_single": 0,
|
||||||
|
"is_skipped": 0,
|
||||||
|
"modified": "2020-05-14 17:40:16.014413",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Setup Taxes",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"reference_document": "Sales Taxes and Charges Template",
|
||||||
|
"show_full_form": 1,
|
||||||
|
"title": "Lets create a Tax Template for Sales ",
|
||||||
|
"validate_action": 0
|
||||||
|
}
|
||||||
@@ -56,14 +56,26 @@ def execute(filters=None):
|
|||||||
row += totals
|
row += totals
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
return columns, data
|
chart = get_chart_data(filters, columns, data)
|
||||||
|
|
||||||
|
return columns, data, None, chart
|
||||||
|
|
||||||
def get_columns(filters):
|
def get_columns(filters):
|
||||||
columns = [
|
columns = [
|
||||||
_(filters.get("budget_against"))
|
{
|
||||||
+ ":Link/%s:150" % (filters.get("budget_against")),
|
'label': _(filters.get("budget_against")),
|
||||||
_("Account") + ":Link/Account:150"
|
'fieldtype': 'Link',
|
||||||
|
'fieldname': 'budget_against',
|
||||||
|
'options': filters.get('budget_against'),
|
||||||
|
'width': 150
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'label': _('Account'),
|
||||||
|
'fieldname': 'Account',
|
||||||
|
'fieldtype': 'Link',
|
||||||
|
'options': 'Account',
|
||||||
|
'width': 150
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
group_months = False if filters["period"] == "Monthly" else True
|
group_months = False if filters["period"] == "Monthly" else True
|
||||||
@@ -79,7 +91,12 @@ def get_columns(filters):
|
|||||||
_("Variance ") + " " + str(year[0])
|
_("Variance ") + " " + str(year[0])
|
||||||
]
|
]
|
||||||
for label in labels:
|
for label in labels:
|
||||||
columns.append(label + ":Float:150")
|
columns.append({
|
||||||
|
'label': label,
|
||||||
|
'fieldtype': 'Float',
|
||||||
|
'fieldname': frappe.scrub(label),
|
||||||
|
'width': 150
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
for label in [
|
for label in [
|
||||||
_("Budget") + " (%s)" + " " + str(year[0]),
|
_("Budget") + " (%s)" + " " + str(year[0]),
|
||||||
@@ -95,14 +112,23 @@ def get_columns(filters):
|
|||||||
else:
|
else:
|
||||||
label = label % formatdate(from_date, format_string="MMM")
|
label = label % formatdate(from_date, format_string="MMM")
|
||||||
|
|
||||||
columns.append(label + ":Float:150")
|
columns.append({
|
||||||
|
'label': label,
|
||||||
|
'fieldtype': 'Float',
|
||||||
|
'fieldname': frappe.scrub(label),
|
||||||
|
'width': 150
|
||||||
|
})
|
||||||
|
|
||||||
if filters["period"] != "Yearly":
|
if filters["period"] != "Yearly":
|
||||||
return columns + [
|
for label in [_("Total Budget"), _("Total Actual"), _("Total Variance")]:
|
||||||
_("Total Budget") + ":Float:150",
|
columns.append({
|
||||||
_("Total Actual") + ":Float:150",
|
'label': label,
|
||||||
_("Total Variance") + ":Float:150"
|
'fieldtype': 'Float',
|
||||||
]
|
'fieldname': frappe.scrub(label),
|
||||||
|
'width': 150
|
||||||
|
})
|
||||||
|
|
||||||
|
return columns
|
||||||
else:
|
else:
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
@@ -173,7 +199,7 @@ def get_dimension_target_details(filters):
|
|||||||
filters.budget_against,
|
filters.budget_against,
|
||||||
filters.company,
|
filters.company,
|
||||||
]
|
]
|
||||||
+ filters.get("budget_against_filter")
|
+ (filters.get("budget_against_filter") or [])
|
||||||
), as_dict=True)
|
), as_dict=True)
|
||||||
|
|
||||||
|
|
||||||
@@ -305,3 +331,49 @@ def get_fiscal_years(filters):
|
|||||||
})
|
})
|
||||||
|
|
||||||
return fiscal_year
|
return fiscal_year
|
||||||
|
|
||||||
|
def get_chart_data(filters, columns, data):
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
|
labels = []
|
||||||
|
|
||||||
|
fiscal_year = get_fiscal_years(filters)
|
||||||
|
group_months = False if filters["period"] == "Monthly" else True
|
||||||
|
|
||||||
|
for year in fiscal_year:
|
||||||
|
for from_date, to_date in get_period_date_ranges(filters["period"], year[0]):
|
||||||
|
if filters['period'] == 'Yearly':
|
||||||
|
labels.append(year[0])
|
||||||
|
else:
|
||||||
|
if group_months:
|
||||||
|
label = formatdate(from_date, format_string="MMM") + "-" \
|
||||||
|
+ formatdate(to_date, format_string="MMM")
|
||||||
|
labels.append(label)
|
||||||
|
else:
|
||||||
|
label = formatdate(from_date, format_string="MMM")
|
||||||
|
labels.append(label)
|
||||||
|
|
||||||
|
no_of_columns = len(labels)
|
||||||
|
|
||||||
|
budget_values, actual_values = [0] * no_of_columns, [0] * no_of_columns
|
||||||
|
for d in data:
|
||||||
|
values = d[2:]
|
||||||
|
index = 0
|
||||||
|
|
||||||
|
for i in range(no_of_columns):
|
||||||
|
budget_values[i] += values[index]
|
||||||
|
actual_values[i] += values[index+1]
|
||||||
|
index += 3
|
||||||
|
|
||||||
|
return {
|
||||||
|
'data': {
|
||||||
|
'labels': labels,
|
||||||
|
'datasets': [
|
||||||
|
{'name': 'Budget', 'chartType': 'bar', 'values': budget_values},
|
||||||
|
{'name': 'Actual Expense', 'chartType': 'bar', 'values': actual_values}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user