Balance Sheet always shows accumulated values from previous fiscal year (#8668)
diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.js b/erpnext/accounts/report/balance_sheet/balance_sheet.js
index 9cd92d4..760fa64 100644
--- a/erpnext/accounts/report/balance_sheet/balance_sheet.js
+++ b/erpnext/accounts/report/balance_sheet/balance_sheet.js
@@ -7,7 +7,8 @@
frappe.query_reports["Balance Sheet"]["filters"].push({
"fieldname": "accumulated_values",
"label": __("Accumulated Values"),
- "fieldtype": "Check"
+ "fieldtype": "Check",
+ "default": 1
});
});
diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py
index 9095d86..2db4ef8 100644
--- a/erpnext/accounts/report/balance_sheet/balance_sheet.py
+++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py
@@ -9,22 +9,19 @@
def execute(filters=None):
period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year,
- filters.periodicity, filters.accumulated_values, filters.company)
+ filters.periodicity, company=filters.company)
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)
+ accumulated_values=filters.accumulated_values)
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)
+ accumulated_values=filters.accumulated_values)
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)
+ accumulated_values=filters.accumulated_values)
provisional_profit_loss, total_credit = get_provisional_profit_loss(asset, liability, equity,
period_list, filters.company)
@@ -114,7 +111,8 @@
opening_balance -= flt(liability[0].get("opening_balance", 0), float_precision)
if equity:
opening_balance -= flt(equity[0].get("opening_balance", 0), float_precision)
-
+
+ opening_balance = flt(opening_balance, float_precision)
if opening_balance:
return _("Previous Financial Year is not closed"),opening_balance
return None,None
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 9ba7711..41d0e48 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -6,8 +6,11 @@
from frappe import _
from frappe.utils import (flt, getdate, get_first_day, get_last_day, date_diff,
add_months, add_days, formatdate, cint)
+from erpnext.accounts.utils import get_fiscal_year
-def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_values=False, company=None):
+
+def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_values=False,
+ company=None, reset_period_on_fy_change=True):
"""Get a list of dict {"from_date": from_date, "to_date": to_date, "key": key, "label": label}
Periodicity can be (Yearly, Quarterly, Monthly)"""
@@ -49,7 +52,8 @@
# if a fiscal year ends before a 12 month period
period.to_date = year_end_date
- period.to_date_fiscal_year = get_date_fiscal_year(period.to_date, company)
+ period.to_date_fiscal_year = get_fiscal_year(period.to_date, company=company)[0]
+ period.from_date_fiscal_year_start_date = get_fiscal_year(period.from_date, company=company)[1]
period_list.append(period)
@@ -65,7 +69,10 @@
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"])
+ if reset_period_on_fy_change:
+ label = get_label(periodicity, opts.from_date_fiscal_year_start_date, opts["to_date"])
+ else:
+ label = get_label(periodicity, period_list[0].from_date, opts["to_date"])
opts.update({
"key": key.replace(" ", "_").replace("-", "_"),
@@ -150,10 +157,6 @@
if entry.posting_date < period_list[0].year_start_date:
d["opening_balance"] = d.get("opening_balance", 0.0) + flt(entry.debit) - flt(entry.credit)
-def get_date_fiscal_year(date, company):
- from erpnext.accounts.utils import get_fiscal_year
- return get_fiscal_year(date, company=company)[0]
-
def accumulate_values_into_parents(accounts, accounts_by_name, period_list, accumulated_values):
"""accumulate children's values in parent accounts"""
for d in reversed(accounts):
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 2c1448c..1721fa9 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -11,7 +11,6 @@
# imported to enable erpnext.accounts.utils.get_account_currency
from erpnext.accounts.doctype.account.account import get_account_currency
-from erpnext.accounts.report.financial_statements import sort_root_accounts
class FiscalYearError(frappe.ValidationError): pass
@@ -652,6 +651,8 @@
@frappe.whitelist()
def get_children():
+ from erpnext.accounts.report.financial_statements import sort_root_accounts
+
args = frappe.local.form_dict
doctype, company = args['doctype'], args['company']
fieldname = frappe.db.escape(doctype.lower().replace(' ','_'))