fix: Do not reduce for empty arrays (#7679)

This commit is contained in:
Deepesh Garg 2019-06-13 10:42:14 +05:30 committed by Faris Ansari
parent f40dc7b840
commit a4e97d4606

View file

@ -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;
}
},