[fix][balance sheet] Check if previous fiscal year is closed
diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py
index 7e05b95..52a358b 100644
--- a/erpnext/accounts/report/balance_sheet/balance_sheet.py
+++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py
@@ -16,6 +16,8 @@
provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity,
period_list, filters.company)
+
+ message = check_opening_balance(asset, liability, equity)
data = []
data.extend(asset or [])
@@ -26,7 +28,7 @@
columns = get_columns(filters.periodicity, period_list, company=filters.company)
- return columns, data
+ return columns, data, message
def get_provisional_profit_loss(asset, liability, equity, period_list, company):
if asset and (liability or equity):
@@ -57,3 +59,14 @@
if has_value:
return provisional_profit_loss
+
+def check_opening_balance(asset, liability, equity):
+ # Check if previous year balance sheet closed
+ opening_balance = flt(asset[0].get("opening_balance", 0))
+ if liability:
+ opening_balance -= flt(liability[0].get("opening_balance", 0))
+ if equity:
+ opening_balance -= flt(asset[0].get("opening_balance", 0))
+
+ if opening_balance:
+ return _("Previous Financial Year is not closed")
\ No newline at end of file
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 3e70a0e..1a59a9d 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -125,14 +125,20 @@
if entry.posting_date <= period.to_date:
if accumulated_values or entry.posting_date >= period.from_date:
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:
+ d["opening_balance"] = d.get("opening_balance", 0.0) + flt(entry.debit) - flt(entry.credit)
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):
if d.parent_account:
for period in period_list:
- accounts_by_name[d.parent_account][period.key] = accounts_by_name[d.parent_account].get(period.key, 0.0) + \
- d.get(period.key, 0.0)
+ accounts_by_name[d.parent_account][period.key] = \
+ accounts_by_name[d.parent_account].get(period.key, 0.0) + d.get(period.key, 0.0)
+
+ accounts_by_name[d.parent_account]["opening_balance"] = \
+ accounts_by_name[d.parent_account].get("opening_balance", 0.0) + d.get("opening_balance", 0.0)
def prepare_data(accounts, balance_must_be, period_list, company_currency):
data = []
@@ -150,13 +156,14 @@
"indent": flt(d.indent),
"year_start_date": year_start_date,
"year_end_date": year_end_date,
- "currency": company_currency
+ "currency": company_currency,
+ "opening_balance": d.get("opening_balance", 0.0) * (1 if balance_must_be=="Debit" else -1)
})
for period in period_list:
- if d.get(period.key):
+ if d.get(period.key) and balance_must_be=="Credit":
# change sign based on Debit or Credit, since calculation is done using (debit - credit)
- d[period.key] *= (1 if balance_must_be=="Debit" else -1)
-
+ d[period.key] *= -1
+
row[period.key] = flt(d.get(period.key, 0.0), 3)
if abs(row[period.key]) >= 0.005: