From 5c9dd425473d7751d7f75aa93f6b1021bdb2a8f3 Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Wed, 14 Jun 2017 10:27:34 +0100 Subject: [PATCH] fixes #9098: don't skip calculation if income or expense is [] (#9267) --- .../profit_and_loss_statement.py | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py index 95085b957ad..6729d672c07 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py @@ -34,28 +34,31 @@ def execute(filters=None): return columns, data, None, chart def get_net_profit_loss(income, expense, period_list, company): - if income and expense: - total = 0 - net_profit_loss = { - "account_name": "'" + _("Net Profit / Loss") + "'", - "account": "'" + _("Net Profit / Loss") + "'", - "warn_if_negative": True, - "currency": frappe.db.get_value("Company", company, "default_currency") - } + total = 0 + net_profit_loss = { + "account_name": "'" + _("Net Profit / Loss") + "'", + "account": "'" + _("Net Profit / Loss") + "'", + "warn_if_negative": True, + "currency": frappe.db.get_value("Company", company, "default_currency") + } - has_value = False + has_value = False - for period in period_list: - net_profit_loss[period.key] = flt(income[-2][period.key] - expense[-2][period.key], 3) + for period in period_list: + total_income = flt(income[-2][period.key], 3) if income else 0 + total_expense = flt(expense[-2][period.key], 3) if expense else 0 - if net_profit_loss[period.key]: - has_value=True + net_profit_loss[period.key] = total_income - total_expense - total += flt(net_profit_loss[period.key]) - net_profit_loss["total"] = total + if net_profit_loss[period.key]: + has_value=True + + total += flt(net_profit_loss[period.key]) + net_profit_loss["total"] = total + + if has_value: + return net_profit_loss - if has_value: - return net_profit_loss def get_chart_data(filters, columns, income, expense, net_profit_loss): x_intervals = ['x'] + [d.get("label") for d in columns[2:]]