Fixing the Problem in Territory & Other Tree DocTypes

As you can see below, I was trying to fetch a report for Northern Region territory (which is a parent for 3 smaller territories, but the problem here is that the system doesn’t sum up all its children’s data…

Is there anything I can do to fix this? Preferably via Custom Script

Yes in the py file, No you don’t need to change the script every time you add a child territory.

You just need to loop the result of the command then get the data in the DOctype where child is equals to the current child in loop

How can I insert this script? I have to insert it into the py file? Does it also mean that I have to update the script every time I create a new child? If yes, well, although it is a hassle, but at least it can fix it.