diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 469726a1b78..478c603dbf5 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -737,6 +737,9 @@ def compute_growth_view_data(data, columns): data_copy = copy.deepcopy(data) for row_idx in range(len(data_copy)): + if not data_copy[row_idx]: + continue + for column_idx in range(1, len(columns)): previous_period_key = columns[column_idx - 1].get("key") current_period_key = columns[column_idx].get("key") @@ -785,13 +788,21 @@ def compute_margin_view_data(data, columns, accumulated_values): for column in columns: curr_period = column.get("key") - base_value = base_row[curr_period] - curr_value = row[curr_period] - if curr_value is None or base_value <= 0: + base_value = base_row.get(curr_period) + curr_value = row.get(curr_period) + + if base_value is None or curr_value is None: data[row_idx][curr_period] = None continue + if base_value == 0: + if curr_value == 0: + data[row_idx][curr_period] = 0 + else: + data[row_idx][curr_period] = None + continue + margin_percent = round((curr_value / base_value) * 100, 2) data[row_idx][curr_period] = margin_percent