Hello, I have 2 fields in a Child Table( “unit” and “packing”) and the field " total" in doctype “factor_table”.
What I am trying to do is to have the following formula cantitate (unit * packing) = total.
And then sum of all total Cells Display in a row named (Sum total) in doctype “factor”.
Hi,
I’m newbie to erpnext and frappe framework also.
but I think your problem could be fix via client script. I just test code below and it works as expected.
frappe.ui.form.on('Your Child Table Name', {
unit(frm,cdt, cdn) {
let doc= locals[cdt][cdn];
doc.total=doc.unit*doc.packing;
frm.refresh_field('Your child table field name');
}
packing(frm,cdt, cdn) {
let doc= locals[cdt][cdn];
doc.total=doc.unit*doc.packing;
frm.refresh_field('Your child table field name');
}
})
@NCP I learn a lot from your previous post and solution. I try my best to learn from official document site, but I cannot find some syntax like frappe.model.set_value.
Could you please provide me link that I can learn more about this kind of feature?
Hello, thank you for your help.
I wrote the script you said. When I enter the selling department and create our first invoice, it calculates and displays the total in the column, but when I save, all the data in the column will be deleted. How can I solve this problem?
Then, how can I write a script that displays the sum of the total column in the sum total row.
@erfaneh_sahraii The client script should be on parent doctype.
Lets assume that the sum field name is total_sum and child table name is items, then the code be
Hello , my parent doctype name is (Factor) and my child table name is (Factor_table).
the sum field name is (sum_total). So I wrote my script like this
frappe.ui.form.on(‘Factor’, {
validate: function(frm) {
let sum_total = 0;
$.each(frm.doc.Factor_table, function(i, d) {
sum_total += flt(d.total)
});
frm.doc.sum_total = sum_total;
}
});
but it didn’t work.
@erfaneh_sahraii What @Pheakdey_Tes1 said is right.
But if you want it to be immediate then the code must be changed, assuming the child table title is Factor Table and it’s name is Factor_table