Please help I tried to run the following custom script but it is not work:
frappe.ui.form.on(“Project test invoice”, “validate”, function(frm) {
set_total_01(frm);
})
frappe.ui.form.on(“sum test table”, “qty_11”, function(frm, cdt, cdn) {
set_total_01(frm);
})
var set_total_01 = function(frm) {
var total_01 = 0.0;
$.each(frm.doc.table_2, function(i, row) {
total_01 += flt(row.qty_11);
})
frm.set.value(“total_01”, total_01);
frm.refresh();
}
parent doctype name is:Project test invoice
parent total field is: total_01
child table name is: sum test table
child table name in parent doctype is: table_2
column to be sum name in child table is: qty_11
frappe.ui.form.on(“sum test table”, “qty_11”, function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.table_2.forEach(function(d) { total += d.qty_11; });
frm.set_value(‘total_01’, total);
refresh_field("total_01");
});
frappe.ui.form.on("sum test table", "qty_11", function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.table_2.forEach(function(d) { total += d.qty_11; });
frm.set_value("total_01", total);
frm.refresh_field("total_01");
});
Sorry @Mohammed_Redha for disturbance.
Shall I use this? Script under parent or child table ?
frappe.ui.form.on(‘Item Color’, {
color_remove: function(frm) {
// Deleting is triggered here
}
frappe.ui.form.on("Project test invoice", {
table2_remove:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.table_2.forEach(function(d) { total += d.qty_11; });
frm.set_value("total_01", total);
refresh_field("total_01");
}
});
frappe.ui.form.on(“Project test invoice”, {
table_2_remove:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.table_2.forEach(function(d) { total += d.qty_11; });
frappe.ui.form.on("sum test table", {
qty_11:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.table_2.forEach(function(d) { total += d.qty_11; });
frm.set_value("total_01", total);
refresh_field("total_01");
},
table2_remove:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.table_2.forEach(function(d) { total += d.qty_11; });
frm.set_value("total_01", total);
refresh_field("total_01");
}
});
Thanks a lot @Mohammed_Redha the following code working properly:
frappe.ui.form.on(“sum test table”, {
qty_11:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.table_2.forEach(function(d) { total += d.qty_11; });
frm.set_value(“total_01”, total);
refresh_field(“total_01”);
},
table_2_remove:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.table_2.forEach(function(d) { total += d.qty_11; });
frm.set_value(“total_01”, total);
refresh_field(“total_01”);
}
});
frappe.ui.form.on(“Project Item”, {
contract_amount:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.scope.forEach(function(d) { total += d.contract_amount; });
frm.set_value(“total_contract_amount”, total);
refresh_field(“total_contract_amount”);
},
scope_remove:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.scope.forEach(function(d) { total += d.contract_amount; });
frm.set_value(“total_contract_amount”, total);
refresh_field(“total_contract_amount”);
}
});
Fields are:
Parent total field is: total_contract_amount
child table name is: Project Item
child table name in parent doctype is: scope
column to be sum name in child table is: contract_amount