Hrs are not fetch automatically

Whi le providing from time and to time details , hrs still blank or 0, how to fetch hours at automatically,i give hours as float.

Hi @Mohamed2335,

It worked properly, please check it.

Thank You!

thanks for your response hours are automatically fetch for other doc type i had problem only on labour allocation

Hi @Mohamed2335,

That for, please apply the client for it.

Please check the syntax and set the field name and doctype accordingly.

frappe.ui.form.on('Child DocType Name', {
	from_time: function(frm, cdt, cdn) {
		calculate_end_time(frm, cdt, cdn);

	to_time: function(frm, cdt, cdn) {
		var child = locals[cdt][cdn];

		if(frm._setting_hours) return;

		var hours = moment(child.to_time).diff(moment(child.from_time), "seconds") / 3600;
		frappe.model.set_value(cdt, cdn, "hours", hours);

	hours: function(frm, cdt, cdn) {
		calculate_end_time(frm, cdt, cdn);

var calculate_end_time = function(frm, cdt, cdn) {
	let child = locals[cdt][cdn];

	if(!child.from_time) {
		// if from_time value is not available then set the current datetime
		frappe.model.set_value(cdt, cdn, "from_time", frappe.datetime.get_datetime_as_string());

	let d = moment(child.from_time);
	if(child.hours) {
		d.add(child.hours, "hours");
		frm._setting_hours = true;
		frappe.model.set_value(cdt, cdn, "to_time",
			d.format(frappe.defaultDatetimeFormat)).then(() => {
			frm._setting_hours = false;

I hope this helps.

Thank You!

no changes sir any mistake can i done?

Please add like

frappe.ui.form.on('Labour Allocation Details', {

And also check the field name is proper or not.

Thank You!

thanks sir