Sum fields amount From Child Table V7

I think I’ve found your problem. You need to put the script in the “Arqueo de Caja” custom script file and point the script at “Arqueo de Caja”.

frappe.ui.form.on("Arqueo de Caja", {
    "cantidad": function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(d.doctype, d.name, "valor", d.denominacion * d.cantidad);
        var total = 0;
        frm.doc.denominaciones.forEach(function(d) { total += d.valor; });
        frm.set_value('balance_real', total);
    }
});

Yes im working on parent doc, theres how the scrips looks like, the funtion from calculating the table lines are working but still i cant ge any value on my balance real field

Try this:

frappe.ui.form.on("Denominaciones", {
    denominacion: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        var total = 0;
        frappe.model.set_value(d.doctype, d.name, "valor", d.denominacion * d.cantidad);
        frm.doc.denominaciones.forEach(function(d) { total += d.valor; });
        frm.set_value('balance_real', total);
    }
});

frappe.ui.form.on("Denominaciones", {
    cantidad: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        var total = 0;
        frappe.model.set_value(d.doctype, d.name, "valor", d.denominacion * d.cantidad);
        frm.doc.denominaciones.forEach(function(d) { total += d.valor; });
        frm.set_value('balance_real', total);
    }
});

@Randy_Lowery Please try this and get back to me, I only have an hour before I have to go offline, and I’d like to see this work for you today.

i haven’t had any luck with the code definitely this line :

frm.doc.denominaciones.forEach(function(d) { total += d.valor; });

isnt updating the value because i tried the same scrip with : for (i = 0; i < [DONOTYETKNOW]; i++) your first postand at least is calculating something. ( the las updated line multiplied by the [DONOTYETKNOW] value.

as for now this is all thats works

for calculating fields within a row.

if i instead use this

frappe.ui.form.on(“Denominaciones”, {
cantidad: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
var total = 0;
frappe.model.set_value(d.doctype, d.name, “valor”, d.denominacion * d.cantidad);
frm.doc.denominaciones.forEach(function(d) { total += d.valor; });
frm.set_value(‘balance_real’, total);
}
});

theres no calculation at all at row level and total field

also tried this one

from this thread Calculate Total Qty of items table of Sales Invoice - #11 by helenelollipops

And still isnt working, but thank for been patient and pointing me out possible solutions.

It’s wierd, because I’ve now got it working on my end. I’ll give you all of the information on my side and we’ll see if that helps I guess.

Functions:

frappe.ui.form.on("Testbed Child", {
    len: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        var total = 0;
        frappe.model.set_value(d.doctype, d.name, "area", d.len * d.wid);
        frm.doc.table.forEach(function(d) { total += d.area; });
        frm.set_value('total_area', total);
    }
});

frappe.ui.form.on("Testbed Child", {
    wid: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        var total = 0;
        frappe.model.set_value(d.doctype, d.name, "area", d.len * d.wid);
        frm.doc.table.forEach(function(d) { total += d.area; });
        frm.set_value('total_area', total);
    }
});

Parent DocType: Testbed DocType A
Child Table Doctype: Testbed Child

Calculation within table: len * wid = area
Calculation outside of table: sum of all areas
Sum field: total_area

thats good news thanks!

see above post.

frappe.ui.form.on("[CHILD TABLE DOCTYPE]", {
    [CHILDTABLEMULTIPLE1]: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        var total = 0;
        frappe.model.set_value(d.doctype, d.name, "[CHILDTABLEPRODUCT]", d.[CHILDTABLEMULTIPLE1] * d.[CHILDTABLEMULTIPLE2]);
        frm.doc.[CHILDTABLEFIELDINPARENT].forEach(function(d) { total += d.[CHILDTABLEPRODUCT]; });
        frm.set_value('[PARENTDOCTYPETOTALFIELD]', total);
    }
});
frappe.ui.form.on("[CHILD TABLE DOCTYPE]", {
    [CHILDTABLEMULTIPLE2]: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        var total = 0;
        frappe.model.set_value(d.doctype, d.name, "[CHILDTABLEPRODUCT]", d.[CHILDTABLEMULTIPLE1] * d.[CHILDTABLEMULTIPLE2]);
        frm.doc.[CHILDTABLEFIELDINPARENT].forEach(function(d) { total += d.[CHILDTABLEPRODUCT]; });
        frm.set_value('[PARENTDOCTYPETOTALFIELD]', total);
    }
});
3 Likes

just to make sure with my values should look like this:

frappe.ui.form.on(“Denominaciones”, {
denominacion: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
var total = 0;
frappe.model.set_value(d.doctype, d.name, “valor”, d.cantidad * d.denominacion);
frm.doc.table.forEach(function(d) { total += d.valor; });
frm.set_value(‘balance_real’, total);
}
});

frappe.ui.form.on(“Denominaciones”, {
cantidad: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
var total = 0;
frappe.model.set_value(d.doctype, d.name, “valor”, d.cantidad * d.denominacion);
frm.doc.table.forEach(function(d) { total += d.valor; });
frm.set_value(‘balance_real’, total);
}
});

still isnt working

instead of frm.doc.table.foreach it should be frm.doc.denominaciones.foreach

@Randy_Lowery

well definetly ill try crating a new table with your fields for testing since i cant figure it out with my own

n o

Well, sorry I couldn’t be of more help. . .

ill update when find it out thank you @cpurbaugh for all the time and trouble :slight_smile:

@Randy_Lowery you can use this .csv file to import my testbed doctypes:

@Randy_Lowery You can use this file to import the custom script:

@cpurbaugh yes you where right the scrip does work what i did for anyone who read this is at Parent doc level recreate my field that is linked to the table denominaciones with the name table and use this scrip

frappe.ui.form.on(“Denominaciones”, {
denominacion: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
var total = 0;
frappe.model.set_value(d.doctype, d.name, “valor”, d.denominacion * d.cantidad);
frm.doc.table.forEach(function(d) { total += d.valor; });
frm.set_value(‘balance_real’, total);
}
});

frappe.ui.form.on(“Denominaciones”, {
cantidad: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
var total = 0;
frappe.model.set_value(d.doctype, d.name, “valor”, d.denominacion * d.cantidad);
frm.doc.table.forEach(function(d) { total += d.valor; });
frm.set_value(‘balance_real’, total);
}
});

thank you i couldn’t figure out without your help.!!

3 Likes

I’m glad I could help!

1 Like