From 443a7c13e46ee9f33e20f1e12256690fb63c338c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 21 Mar 2016 12:46:15 +0530 Subject: [PATCH] [fix][balance sheet] Check if previous fiscal year is closed --- .../report/balance_sheet/balance_sheet.py | 15 ++++++++++++++- .../accounts/report/financial_statements.py | 19 +++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py index 7e05b9519b..52a358bd8b 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py @@ -16,6 +16,8 @@ def execute(filters=None): 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 @@ def execute(filters=None): 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 @@ def get_provisional_profit_loss(asset, liability, equity, period_list, company): 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 3e70a0eef6..1a59a9df0a 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -125,14 +125,20 @@ 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: 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 @@ def prepare_data(accounts, balance_must_be, period_list, company_currency): "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: