Is this Organization Chart control generic enough to be used for other hierarchical doctypes ?
https://github.com/frappe/erpnext/pull/26261
1 Like
Hi Guimorin,
I havenât read the full code yet and analyzed it, but looks like it is tied to the âreports toâ field and the âEmployeeâ DocType.
https://github.com/frappe/erpnext/pull/26261#issuecomment-873596585
frappe.pages['organizational-chart'].on_page_load = function(wrapper) {
frappe.ui.make_app_page({
parent: wrapper,
title: __('Organizational Chart'),
single_column: true
});
$(wrapper).bind('show', () => {
frappe.require('/assets/js/hierarchy-chart.min.js', () => {
let organizational_chart = undefined;
let method = 'erpnext.hr.page.organizational_chart.organizational_chart.get_children';
if (frappe.is_mobile()) {
organizational_chart = new erpnext.HierarchyChartMobile('Employee', wrapper, method);
} else {
organizational_chart = new erpnext.HierarchyChart('Employee', wrapper, method);
}
organizational_chart.show();
});
});
This file has been truncated. show original
So I donât believe itâs generic yet.
Yes I understand, this file is the page in hr module.
But I was hoping the file hierarchy_chart_desktop.js to be generic and reusable, yet I see a breadcrumb âHRâ added here, so I am not sure:
parent: node.parent_id,
connections: node.connections,
is_mobile: false
});
node.parent.append(node_card);
node.$link = $(`#${node.id}`);
}
show() {
frappe.breadcrumbs.add('HR');
this.setup_actions();
if ($(`[data-fieldname="company"]`).length) return;
let me = this;
let company = this.page.add_field({
fieldtype: 'Link',
options: 'Company',
fieldname: 'company',
placeholder: __('Select Company'),
Does not appear to be generic. There are references to âHRâ as you pointed out as well as âEmployeeâ in the code.
alonbr
August 25, 2021, 1:48pm
#5
Perhaps you can duplicate the Doctype along with itâs scripts and try to maneuver your way around this breadcrumb⌠possibly even posting back hereâŚ
alonbr
August 25, 2021, 1:50pm
#6
I was thinking something in the line of adding a field for reference doctype, from which a specific hierarchy can be obtained
alonbr
August 25, 2021, 1:52pm
#7
also there is a reference to Employee.âreports_toâ field:
is_expandable = frappe.db.count('Employee', filters={'reports_to': employee.get('id')})
employee.connections = get_connections(employee.id)
employee.expandable = 1 if is_expandable else 0
return employees
def get_connections(employee):
num_connections = 0
connections = frappe.get_list('Employee', filters=[
['reports_to', '=', employee]
])
num_connections += len(connections)
while connections:
for entry in connections:
connections = frappe.get_list('Employee', filters=[
['reports_to', '=', entry.name]
])
num_connections += len(connections)
IMO: Best thing would be to extract what this Functionality needs and define a Interface or use Dependency Injection/Inversion of Control to dry this and let other objects implement it.
I have not spent enough time looking at some other core functionality code to determine what has been the frameworkâs approach to it.
Thanks for your inputs, but I am not referencing the organizational_chart custom page in the HR module you are all posting about.
Iâm speaking of the HierarchyChart, which seems mostly generic, except for the HR breadcrumbs reference. Iâll ask on github why itâs there, probably an error.
parent: node.parent_id,
connections: node.connections,
is_mobile: false
});
node.parent.append(node_card);
node.$link = $(`#${node.id}`);
}
show() {
frappe.breadcrumbs.add('HR');
this.setup_actions();
if ($(`[data-fieldname="company"]`).length) return;
let me = this;
let company = this.page.add_field({
fieldtype: 'Link',
options: 'Company',
fieldname: 'company',
placeholder: __('Select Company'),
https://github.com/frappe/erpnext/issues/27153
bluesky
November 30, 2021, 12:17am
#11
Great idea to reuse the organizational chart for other hierarchical doctypes!