How can I calculate total budget allocated

Hello fellows,
How can I calculate a total budget against a particular cost center or project?
For instance I have added several rows in my budget, now I was to get the total amount from all rows,

Please help on how to achieve that?


Budget doctype

Budget Account doctype

I know it might require custom script to achieve this, but I don’t know how.
can I get at-least an example anyone?


hi @deatram,

Create Total Amount field in your Parent doctype, (After Table.)
And Try below script,

frappe.ui.form.on("Budget Account", "budget_amount", function(frm, cdt, cdn) {

       var acc = frm.doc.accounts;
       var total = 0;
       for(var i in acc) {
    	total = total + acc[i].budget_amount;

1 Like

Dear Deatram,

Shahid responded faster than me. However, Here’s the script:

frappe.ui.form.on(“Budget Account”, “budget_amount”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_budget = 0;
$.each(frm.doc.accounts || [], function(i, d) {
total_budget += flt(d.budget_amount);

Apply this on the budget doctype on custom script form and you’re good to go. A word of warning, This will not update any past data. Will work just fine on the new entries.

1 Like

hello @rushikesherp .thank you very much it worked. I can now see my total budget

@shahid thank you too :grinning::grinning::grinning::grinning:

i have seen other add this script at the end.


What does the line of script do?

to immediate update the total budget once you add new budget account.