How do I add total hours in the table in custom script? in h:m format

you will have to add those values in Hours column and set Total OT Hours to that value.

a sample code might help :slight_smile:

is this your custom document or a default document ?

Custom document

@Raymart_Gomez you can use data type for the column and the when add the date in the format you want as string
time.strftime(“h:m”)

I Tried this code but it doenst work :3

frappe.ui.form.on(“OT Details”, {
hours:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var thr = 0;
var tmn = 0;
frm.doc.ot_details.forEach(function(d) {
var hours=minutes=seconds=total=0
var hours=moment(d.hours, “HH:mm:ss”);
hours = parseInt(duration.asHours());
minutes = parseInt(duration.asMinutes())%60;
thr += hours;
tmn += minutes;
});
frappe.model.set_value(“total_ot_hours”,thr+“:”+tmn);
frm.refresh_field(“total_ot_hours”);
}
})

in file
/opt/frappe/frappe-bench/apps/frappe/frappe/desk/query_report.py
replace add_total_row function with this function

def add_total_row(result, columns, meta = None):
	total_row = [""]*len(columns)
	has_percent = []
	for i, col in enumerate(columns):
		fieldtype, options = None, None
		if isinstance(col, string_types):
			if meta:
				# get fieldtype from the meta
				field = meta.get_field(col)
				if field:
					fieldtype = meta.get_field(col).fieldtype
			else:
				col = col.split(":")
				if len(col) > 1:
					if col[1]:
						fieldtype = col[1]
						if "/" in fieldtype:
							fieldtype, options = fieldtype.split("/")
					else:
						fieldtype = "Data"
		else:
			fieldtype = col.get("fieldtype")
			options = col.get("options")

		for row in result:
			if fieldtype in ["Currency", "Int", "Float", "Percent"] and flt(row[i]):
				total_row[i] = flt(total_row[i]) + flt(row[i])

			if fieldtype == "Percent" and i not in has_percent:
				has_percent.append(i)

			if fieldtype == "Time" and row[i]:
				if not total_row[i]:
					total_row[i]=timedelta(hours=0,minutes=0,seconds=0)
				total_row[i] =  total_row[i] + row[i]

		if fieldtype=="Link" and options == "Currency":
			total_row[i] = result[0][i]

	for i in has_percent:
		total_row[i] = flt(total_row[i]) / len(result)

	first_col_fieldtype = None
	if isinstance(columns[0], string_types):
		first_col = columns[0].split(":")
		if len(first_col) > 1:
			first_col_fieldtype = first_col[1].split("/")[0]
	else:
		first_col_fieldtype = columns[0].get("fieldtype")

	if first_col_fieldtype not in ["Currency", "Int", "Float", "Percent", "Date"]:
		if first_col_fieldtype == "Link":
			total_row[0] = "'" + _("Total") + "'"
		else:
			total_row[0] = _("Total")

	result.append(total_row)
	return result