diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.js b/erpnext/accounts/report/balance_sheet/balance_sheet.js index a20d47c7849..9cd92d43674 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.js +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.js @@ -3,6 +3,12 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() { frappe.query_reports["Balance Sheet"] = erpnext.financial_statements; + + frappe.query_reports["Balance Sheet"]["filters"].push({ + "fieldname": "accumulated_values", + "label": __("Accumulated Values"), + "fieldtype": "Check" + }); }); diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py index 4325afcd291..9095d8619b6 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py @@ -8,11 +8,23 @@ from frappe.utils import flt, cint from erpnext.accounts.report.financial_statements import (get_period_list, get_columns, get_data) def execute(filters=None): - period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity, filters.company) + period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, + filters.periodicity, filters.accumulated_values, filters.company) - asset = get_data(filters.company, "Asset", "Debit", period_list, only_current_fiscal_year=False) - liability = get_data(filters.company, "Liability", "Credit", period_list, only_current_fiscal_year=False) - equity = get_data(filters.company, "Equity", "Credit", period_list, only_current_fiscal_year=False) + asset = get_data(filters.company, "Asset", "Debit", period_list, + only_current_fiscal_year=False, filters=filters, + accumulated_values=filters.accumulated_values, + ignore_closing_entries=True, ignore_accumulated_values_for_fy=True) + + liability = get_data(filters.company, "Liability", "Credit", period_list, + only_current_fiscal_year=False, filters=filters, + accumulated_values=filters.accumulated_values, + ignore_closing_entries=True, ignore_accumulated_values_for_fy=True) + + equity = get_data(filters.company, "Equity", "Credit", period_list, + only_current_fiscal_year=False, filters=filters, + accumulated_values=filters.accumulated_values, + ignore_closing_entries=True, ignore_accumulated_values_for_fy=True) provisional_profit_loss, total_credit = get_provisional_profit_loss(asset, liability, equity, period_list, filters.company) @@ -43,9 +55,9 @@ def execute(filters=None): if total_credit: data.append(total_credit) - columns = get_columns(filters.periodicity, period_list, company=filters.company) + columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, company=filters.company) - chart = get_chart_data(columns, asset, liability, equity) + chart = get_chart_data(filters, columns, asset, liability, equity) return columns, data, message, chart @@ -107,7 +119,7 @@ def check_opening_balance(asset, liability, equity): return _("Previous Financial Year is not closed"),opening_balance return None,None -def get_chart_data(columns, asset, liability, equity): +def get_chart_data(filters, columns, asset, liability, equity): x_intervals = ['x'] + [d.get("label") for d in columns[2:]] asset_data, liability_data, equity_data = [], [], [] @@ -128,9 +140,14 @@ def get_chart_data(columns, asset, liability, equity): if equity_data: columns.append(["Equity"] + equity_data) - return { + chart = { "data": { 'x': 'x', 'columns': columns } } + + if not filters.accumulated_values: + chart["chart_type"] = "bar" + + return chart \ No newline at end of file diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py index d2c8c3e5f1c..f55d1927318 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.py +++ b/erpnext/accounts/report/cash_flow/cash_flow.py @@ -11,7 +11,7 @@ from erpnext.accounts.utils import get_fiscal_year def execute(filters=None): period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, - filters.periodicity, filters.company) + filters.periodicity, filters.accumulated_values, filters.company) operation_accounts = { "section_name": "Operations", diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 80b0bf25587..9ba7711f0b5 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -4,9 +4,10 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import flt, getdate, get_first_day, add_months, add_days, formatdate +from frappe.utils import (flt, getdate, get_first_day, get_last_day, date_diff, + add_months, add_days, formatdate, cint) -def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, company): +def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_values=False, company=None): """Get a list of dict {"from_date": from_date, "to_date": to_date, "key": key, "label": label} Periodicity can be (Yearly, Quarterly, Monthly)""" @@ -58,11 +59,14 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, company): # common processing for opts in period_list: key = opts["to_date"].strftime("%b_%Y").lower() - if periodicity == "Monthly": + if periodicity == "Monthly" and not accumulated_values: label = formatdate(opts["to_date"], "MMM YYYY") else: - label = get_label(periodicity, opts["from_date"], opts["to_date"]) - + if not accumulated_values: + label = get_label(periodicity, opts["from_date"], opts["to_date"]) + else: + label = get_label(periodicity, period_list[0]["from_date"], opts["to_date"]) + opts.update({ "key": key.replace(" ", "_").replace("-", "_"), "label": label, @@ -139,7 +143,8 @@ def calculate_values(accounts_by_name, gl_entries_by_account, period_list, accum if entry.posting_date <= period.to_date: if (accumulated_values or entry.posting_date >= period.from_date) and \ - (not ignore_accumulated_values_for_fy or entry.fiscal_year == period.to_date_fiscal_year): + (not ignore_accumulated_values_for_fy or + entry.fiscal_year == period.to_date_fiscal_year): d[period.key] = d.get(period.key, 0.0) + flt(entry.debit) - flt(entry.credit) if entry.posting_date < period_list[0].year_start_date: diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py index 02dc8700356..95085b957ad 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py @@ -9,12 +9,15 @@ from erpnext.accounts.report.financial_statements import (get_period_list, get_c def execute(filters=None): period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, - filters.periodicity, filters.company) + filters.periodicity, filters.accumulated_values, filters.company) income = get_data(filters.company, "Income", "Credit", period_list, filters = filters, - accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) + accumulated_values=filters.accumulated_values, + ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) + expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters, - accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) + accumulated_values=filters.accumulated_values, + ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)