How to add/multiply values and display them

I don’t know if in frappe cloud you can add client script, but if you can, you can try this.

You will have to modify it with the name of your doctype, your fields, etc.

frappe.ui.form.on('YourDocType', {
    refresh(frm) {
        // Code that runs when the form is refreshed
    }
});

frappe.ui.form.on('Item', { // Replace 'Item' with the actual name of your Child Table DocType
    quantity(frm, cdt, cdn) {
        // Runs when the "quantity" field in any row of the "items" Child Table changes
        calculate_amount(frm, cdt, cdn);
    },
    rate(frm, cdt, cdn) {
        // Runs when the "rate" field in any row of the "items" Child Table changes
        calculate_amount(frm, cdt, cdn);
    }
});

function calculate_amount(frm, cdt, cdn) {
    var child = locals[cdt][cdn];
    var amount = child.rate * child.quantity;

    // Set the value of the "amount" field in the current row of the Child Table
    frappe.model.set_value(cdt, cdn, 'amount', amount);
}

1 Like