diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py index d2626cddc1..5547b49ce9 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py @@ -14,17 +14,31 @@ def execute(filters=None): 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) - provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity, + provisional_profit_loss,total_credit = get_provisional_profit_loss(asset, liability, equity, period_list, filters.company) - message = check_opening_balance(asset, liability, equity) + message,opening_balance = check_opening_balance(asset, liability, equity) data = [] data.extend(asset or []) data.extend(liability or []) data.extend(equity or []) + if opening_balance and round(opening_balance,2) !=0: + unclosed ={ + "account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'", + "account": None, + "warn_if_negative": True, + "currency": frappe.db.get_value("Company", filters.company, "default_currency") + } + for period in period_list: + unclosed[period.key] = opening_balance + provisional_profit_loss[period.key] = provisional_profit_loss[period.key] - opening_balance + unclosed["total"]=opening_balance + data.append(unclosed) + if provisional_profit_loss: data.append(provisional_profit_loss) + data.append(total_credit) columns = get_columns(filters.periodicity, period_list, company=filters.company) @@ -34,14 +48,20 @@ def execute(filters=None): def get_provisional_profit_loss(asset, liability, equity, period_list, company): if asset and (liability or equity): - total=0 + total = total_row_total=0 + currency = frappe.db.get_value("Company", company, "default_currency") provisional_profit_loss = { "account_name": "'" + _("Provisional Profit / Loss (Credit)") + "'", "account": None, "warn_if_negative": True, - "currency": frappe.db.get_value("Company", company, "default_currency") + "currency": currency + } + total_row = { + "account_name": "'" + _("Total (Credit)") + "'", + "account": None, + "warn_if_negative": True, + "currency": currency } - has_value = False for period in period_list: @@ -52,15 +72,20 @@ def get_provisional_profit_loss(asset, liability, equity, period_list, company): effective_liability += flt(equity[-2].get(period.key)) provisional_profit_loss[period.key] = flt(asset[-2].get(period.key)) - effective_liability + total_row[period.key] = effective_liability + provisional_profit_loss[period.key] if provisional_profit_loss[period.key]: has_value = True total += flt(provisional_profit_loss[period.key]) provisional_profit_loss["total"] = total + + total_row_total += flt(total_row[period.key]) + total_row["total"] = total_row_total if has_value: - return provisional_profit_loss + return provisional_profit_loss, total_row + return None,total_row def check_opening_balance(asset, liability, equity): # Check if previous year balance sheet closed @@ -73,7 +98,8 @@ def check_opening_balance(asset, liability, equity): opening_balance -= flt(equity[0].get("opening_balance", 0)) if opening_balance: - return _("Previous Financial Year is not closed") + return _("Previous Financial Year is not closed"),opening_balance + return None,None def get_chart_data(columns, asset, liability, equity): x_intervals = ['x'] + [d.get("label") for d in columns[2:]] diff --git a/erpnext/accounts/report/trial_balance/trial_balance.js b/erpnext/accounts/report/trial_balance/trial_balance.js index 9943e5d0e3..ff198e9d3e 100644 --- a/erpnext/accounts/report/trial_balance/trial_balance.js +++ b/erpnext/accounts/report/trial_balance/trial_balance.js @@ -55,6 +55,11 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() { "label": __("Show zero values"), "fieldtype": "Check" }, + { + "fieldname": "show_unclosed_fy_pl_balances", + "label": __("Show unclosed fiscal year's P&L balances"), + "fieldtype": "Check" + } ], "formatter": erpnext.financial_statements.formatter, "tree": true, diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py index 5401902443..7609d1d95b 100644 --- a/erpnext/accounts/report/trial_balance/trial_balance.py +++ b/erpnext/accounts/report/trial_balance/trial_balance.py @@ -87,8 +87,10 @@ def get_opening_balances(filters): def get_rootwise_opening_balances(filters, report_type): - additional_conditions = " and posting_date >= %(year_start_date)s" \ - if report_type == "Profit and Loss" else "" + additional_conditions = "" + if not filters.show_unclosed_fy_pl_balances: + additional_conditions = " and posting_date >= %(year_start_date)s" \ + if report_type == "Profit and Loss" else "" if not flt(filters.with_period_closing_entry): additional_conditions += " and ifnull(voucher_type, '')!='Period Closing Voucher'"