Total not calculating

I have created a new Doctype for the module Education. When I’m trying to add the table Fee component it is not giving the total.

Attached image for your reference;

U can write the client script on your custom doctype so please write the custom client script for total

Please check this

1 Like

Check the simple syntax:

Hello again,

Data is fetching properly but it is not reading the second created item. It only fetches the record from the first one.

Like for e.g. I have created 2 fee structure and divided them on student category field. When I’m selecting any student category it is fetching same same for all the categories.

What can be the reason behind this?

Can you please suggest for this.

Please share your code so we will resolve your query

1 Like

frappe.ui.form.on(‘Ksa Fees’, {
student_category: function(frm) {
// frappe.db.get_value(“Sales Invoice”, {‘name’: frm.doc.sales_invoice_id}, [‘customer’, ‘posting_date’, ‘company’], function(value) {
// frm.set_value(‘customer’, value.customer);
// frm.set_value(‘invoice_date’, value.posting_date);
// frm.set_value(‘company’, value.company);
// });

    if (frm.doc.student_category) {
        frappe.call({
            method: 'frappe.client.get',
            args: {
                doctype: "Fee Structure",
                filters: {
                    name: frm.doc.fee_structure_id
                }
            },
            callback: function(r) {
                if (r.message) {
                    console.log("------------", r.message);
                    
                    
                    r.message.components.forEach(function(component) {
                        var child = frm.add_child('f_co');
                        child.fees_category = component.fees_category
                        child.amount = component.amount
                        child.discount = component.discount
                        child.total = component.total
                        
                    });
                    frm.refresh_field('f_co');
                        
                    
                }

                
            }
        });
    }
    }

});

I have updated the code using GPT and now the debug is getting me both the data on selection but it is not printing on the table.

Below are snapshots for reference;

frappe.ui.form.on(‘Ksa Fees’, {
student_category: function(frm) {
if (frm.doc.student_category) {
frappe.call({
method: ‘frappe.client.get_list’,
args: {
doctype: “Fee Structure”,
filters: {
student_category: frm.doc.student_category // Filter by student category
},
fields: [‘name’, ‘components’]
},
callback: function(r) {
if (r.message && r.message.length > 0) {
// Debugging: log the response to ensure we’re getting the correct data
console.log(“Response received:”, r.message);

                    var fee_structure = r.message[0]; // Assuming you only need the first record

                    if (fee_structure.components && fee_structure.components.length > 0) {
                        // Clear the child table before adding new entries
                        frm.clear_table('f_co');

                        fee_structure.components.forEach(function(component) {
                            var child = frm.add_child('f_co');
                            child.fees_category = component.fees_category;
                            child.amount = component.amount;
                            child.discount = component.discount;
                            child.total = component.total;
                        });
                        frm.refresh_field('f_co');
                    } else {
                        frappe.msgprint(__('No components found for the selected student category.'));
                    }
                } else {
                    frappe.msgprint(__('No fee structure found for the selected student category.'));
                }
            }
        });
    }
}

});

Here is the updated code.

Please check the video, maybe help you!

Yes I have done the work using your code. But the problem is it is not fetching data from our type as I mentioned above, if you can check my code please.

It seems like you’ve received the response correctly. Now, you need to debug each line to find the issue. I believe it’s not just about the code; you should learn and understand how to set the values by watching the video. Copy-pasting code sometimes doesn’t work. That’s why I didn’t provide the code in the video. Users often request the code, but without understanding the concept, they just paste it, leading to issues like this. :wink:

Definitely brother, I’m not the programmer but I learnt a lot always from your responses and fixes my issues. I have done have way to my target let me figure out more to get the rest.

Many thanks, In case if I stuck some where I will try you ping you again please.