Hello
How can I create a tree structure report via a script report?
I know the Trial Balance report is a tree structure report but I am not able to create the same report.
can anyone explain to me this basic structure
"formatter": erpnext.financial_statements.formatter,
"tree": true,
"name_field": "what_should_come_here",
"parent_field": "what_should_come_here",
"initial_depth": 3
Yes for reference please see trial balance report structure
Thanks for your reply
my case i want to build tree structure for Tasks
so in Trial balance report i found below line which responsible to create this structure
accounts, accounts_by_name, parent_children_map = filter_accounts(accounts)
how can i change it to be task not account
thanks in Advance
Hi,
Adapt your report_name.js
similar to this
frappe.query_reports["Report_name"] = {
"filters": [
{
fieldname: 'company',
label: __('Company'),
fieldtype: 'Link',
options: 'Company',
},
],
"treeView": true,
"name_field": "task",
"parent_field": "parent_task",
"initial_depth": 2
};
Hey @Nader_Adel, Sorry for the late reply I was busy with other tasks.
So what I have done is
frappe.query_reports["Query Report"] = {
"filters": [
{} ],
"formatter": function (row, cell, value, columnDef, dataContext, default_formatter) {
if (columnDef.df.fieldname == "account") {
value = dataContext.account;
columnDef.df.is_tree = true;
}
value = default_formatter(row, cell, value, columnDef, dataContext);
if (!dataContext.parent_account) {
var $value = $(value).css("font-weight", "bold");
if (dataContext.warn_if_negative && dataContext[columnDef.df.fieldname] < 0) {
$value.addClass("text-danger");
}
value = $value.wrap("<p></p>").parent().html();
}
return value
},
"tree": true,
"name_field": "account",
"parent_field": "parent_account",
"initial_depth": 1
}
So now from the python file make dict structure like
{'account': first_account, 'parent_account': parent_key,
'indent': 0, 'has_value': True,}
If Parent has a value then children then has_value should be True otherwise False.
indent is the level how the tree structure will be shown (means with how be tabs spaces zero means no space)
I hope this solve this Query
Thanks & Regards
Rohan Jain