From 04fe76bf832a4217dc408da762a6aee9a9fcc4d4 Mon Sep 17 00:00:00 2001 From: Ahmed Reda Abukhatwa Date: Thu, 30 Apr 2026 19:47:19 +0300 Subject: [PATCH] fix(profit-and-loss-statement-report): margin calculation the report showing null% for empty cell (cherry picked from commit df6fd782b749480153fd28415e8fe877af12d272) --- erpnext/accounts/report/financial_statements.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 469726a1b78..f03d35dbb5a 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -785,11 +785,19 @@ 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: - data[row_idx][curr_period] = None + 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] = "N/A" + continue + + if base_value == 0: + if curr_value == 0: + data[row_idx][curr_period] = "" + else: + data[row_idx][curr_period] = "N/A" continue margin_percent = round((curr_value / base_value) * 100, 2)