From a4e97d4606944a9b9e4bb11e4e0e8737a511d019 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Thu, 13 Jun 2019 10:42:14 +0530 Subject: [PATCH] fix: Do not reduce for empty arrays (#7679) --- frappe/public/js/frappe/misc/utils.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/frappe/public/js/frappe/misc/utils.js b/frappe/public/js/frappe/misc/utils.js index 76cc71c73b..6e180cfcbc 100644 --- a/frappe/public/js/frappe/misc/utils.js +++ b/frappe/public/js/frappe/misc/utils.js @@ -660,13 +660,18 @@ Object.assign(frappe.utils, { }, report_column_total: function(values, column, type) { - if (column.column.fieldtype == "Percent" || type === "mean") { - return values.reduce((a, b) => a + flt(b)) / values.length; - } else if (column.column.fieldtype == "Int") { - return values.reduce((a, b) => a + cint(b)); - } else if (frappe.model.is_numeric_field(column.column.fieldtype)) { - return values.reduce((a, b) => a + flt(b)); - } else { + if (values.length > 0) { + if (column.column.fieldtype == "Percent" || type === "mean") { + return values.reduce((a, b) => a + flt(b)) / values.length; + } else if (column.column.fieldtype == "Int") { + return values.reduce((a, b) => a + cint(b)); + } else if (frappe.model.is_numeric_field(column.column.fieldtype)) { + return values.reduce((a, b) => a + flt(b)); + } else { + return null; + } + } + else { return null; } },