From ea3b342dded4820ecc0f227f0a31dc3d38d92fdf Mon Sep 17 00:00:00 2001 From: robert schouten Date: Mon, 12 Sep 2016 14:37:58 +0800 Subject: [PATCH 1/2] fix display unclosed values for trial/balance/sheet --- .../report/balance_sheet/balance_sheet.py | 40 +++++++++++++++---- .../report/trial_balance/trial_balance.py | 3 +- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py index d2626cddc1..5d8fe01475 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_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_total += flt(total_row[period.key]) + total_row["total"] = total_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.py b/erpnext/accounts/report/trial_balance/trial_balance.py index 5401902443..b4babcde8e 100644 --- a/erpnext/accounts/report/trial_balance/trial_balance.py +++ b/erpnext/accounts/report/trial_balance/trial_balance.py @@ -87,8 +87,7 @@ 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 flt(filters.with_period_closing_entry): additional_conditions += " and ifnull(voucher_type, '')!='Period Closing Voucher'" From 1d8d93d9ad113a6ae894d5173c788908eb02454a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 12 Sep 2016 17:43:14 +0530 Subject: [PATCH 2/2] Update balance_sheet.py --- erpnext/accounts/report/balance_sheet/balance_sheet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py index 5d8fe01475..5547b49ce9 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py @@ -48,7 +48,7 @@ def execute(filters=None): def get_provisional_profit_loss(asset, liability, equity, period_list, company): if asset and (liability or equity): - total = total_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)") + "'", @@ -80,8 +80,8 @@ def get_provisional_profit_loss(asset, liability, equity, period_list, company): total += flt(provisional_profit_loss[period.key]) provisional_profit_loss["total"] = total - total_total += flt(total_row[period.key]) - total_row["total"] = total_total + total_row_total += flt(total_row[period.key]) + total_row["total"] = total_row_total if has_value: return provisional_profit_loss, total_row