fixes #9098: don't skip calculation if income or expense is [] (#9267)

This commit is contained in:
tundebabzy
2017-06-14 10:27:34 +01:00
committed by Nabin Hait
parent 4c0f9dac94
commit 5c9dd42547

View File

@@ -34,28 +34,31 @@ def execute(filters=None):
return columns, data, None, chart return columns, data, None, chart
def get_net_profit_loss(income, expense, period_list, company): def get_net_profit_loss(income, expense, period_list, company):
if income and expense: total = 0
total = 0 net_profit_loss = {
net_profit_loss = { "account_name": "'" + _("Net Profit / Loss") + "'",
"account_name": "'" + _("Net Profit / Loss") + "'", "account": "'" + _("Net Profit / Loss") + "'",
"account": "'" + _("Net Profit / Loss") + "'", "warn_if_negative": True,
"warn_if_negative": True, "currency": frappe.db.get_value("Company", company, "default_currency")
"currency": frappe.db.get_value("Company", company, "default_currency") }
}
has_value = False has_value = False
for period in period_list: for period in period_list:
net_profit_loss[period.key] = flt(income[-2][period.key] - expense[-2][period.key], 3) 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]: net_profit_loss[period.key] = total_income - total_expense
has_value=True
total += flt(net_profit_loss[period.key]) if net_profit_loss[period.key]:
net_profit_loss["total"] = total 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): def get_chart_data(filters, columns, income, expense, net_profit_loss):
x_intervals = ['x'] + [d.get("label") for d in columns[2:]] x_intervals = ['x'] + [d.get("label") for d in columns[2:]]