child table : Sprint Task
parent table:Sprints
I want to calculate the total_time from child table and want to assign to parent table .Please help me
child table : Sprint Task
parent table:Sprints
I want to calculate the total_time from child table and want to assign to parent table .Please help me
This may be helpful:
Hi simigireesh,
a good resource is Developer Cheatsheet · frappe/frappe Wiki · GitHub
Attach your custom script to your Sprints DocType, then loop through your sprint task items, add their times and subsequently write into the total field. Something like
function calculate_total_time() {
var tasks = cur_frm.doc.tasks; // assuming your child table is called tasks
var total_time = 0; // initialise time
// loop through items of subtable
tasks.forEach(function(entry) {
if (entry.time_spent != null) {
total_time += entry.time_spent;
}
});
// write result to doc
cur_frm.set_value("total_time", total_time);
}
As a trigger for your function, use something like this in the custom script
frappe.ui.form.on("Sprint", {
tasks: function(frm) {
calculate_total_time()
}
});
If that doesn’t do the job, resort to MutationObservers…
Hope this helps.
frappe.ui.form.on(“Sprint Task”, “expected_time”, function(frm, cdt, cdn) {
//console.log(frm.doc.tasks)
var hrs = frm.doc.tasks
var total = 0
for(var i in hrs) {
total = total + parseInt(hrs[i].expected_time);
}
//alert(total);
cur_frm.set_value(“total_time”,total)
});
frappe.ui.form.on(‘Sprint Task’, {
tasks_add: function(frm) {
},
tasks_remove:function(frm){
calc_total_exp_time(frm);
},
});
frappe.ui.form.on(“Sprint Task”, “expected_time”, function(frm, cdt, cdn)
{
calc_total_exp_time(frm);
});
function calc_total_exp_time(frm)
{
console.log(frm.doc.tasks)
var hrs = frm.doc.tasks
var total = 0
for(var i in hrs)
{
total = total + parseInt(hrs[i].expected_time);
}
cur_frm.set_value(“total_time”,total)
}