From 3c4aa2a3ddeca1f8e11a7697e628d3da0289b77e Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 3 Mar 2022 20:28:57 +0100 Subject: [PATCH] refactor: Simplify logic in `handle_duration_fieldtype_values` --- frappe/desk/query_report.py | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/frappe/desk/query_report.py b/frappe/desk/query_report.py index 61913f3e05..c9c2d4a4cc 100644 --- a/frappe/desk/query_report.py +++ b/frappe/desk/query_report.py @@ -371,28 +371,30 @@ def handle_duration_fieldtype_values(result, columns): if isinstance(col, str): col = col.split(":") if len(col) > 1: - if col[1]: - fieldtype = col[1] - if "/" in fieldtype: - fieldtype, options = fieldtype.split("/") - else: - fieldtype = "Data" + if not col[1]: + continue + + fieldtype = col[1] + if "/" in fieldtype: + fieldtype = fieldtype.split("/")[0] else: fieldtype = col.get("fieldtype") - if fieldtype == "Duration": - for entry in range(0, len(result)): - row = result[entry] - if isinstance(row, dict): - val_in_seconds = row[col.fieldname] - if val_in_seconds: - duration_val = format_duration(val_in_seconds) - row[col.fieldname] = duration_val - else: - val_in_seconds = row[i] - if val_in_seconds: - duration_val = format_duration(val_in_seconds) - row[i] = duration_val + if fieldtype != "Duration": + continue + + for entry in range(0, len(result)): + row = result[entry] + if isinstance(row, dict): + val_in_seconds = row[col.fieldname] + if val_in_seconds: + duration_val = format_duration(val_in_seconds) + row[col.fieldname] = duration_val + else: + val_in_seconds = row[i] + if val_in_seconds: + duration_val = format_duration(val_in_seconds) + row[i] = duration_val return result