brotherton-erpnext/erpnext/hr/page/organizational_chart/organizational_chart.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.2 KiB
Python
Raw Normal View History

2021-06-20 07:12:06 +00:00
from __future__ import unicode_literals
import frappe
@frappe.whitelist()
def get_children(parent=None, company=None):
2021-06-20 07:12:06 +00:00
filters = [['status', '!=', 'Left']]
if company and company != 'All Companies':
filters.append(['company', '=', company])
if parent and company and parent != company:
2021-06-20 07:12:06 +00:00
filters.append(['reports_to', '=', parent])
else:
filters.append(['reports_to', '=', ''])
employees = frappe.get_list('Employee',
fields=['employee_name as name', 'name as id', 'reports_to', 'image', 'designation as title'],
filters=filters,
order_by='name'
)
2021-06-20 07:12:06 +00:00
for employee in employees:
is_expandable = frappe.db.count('Employee', filters={'reports_to': employee.get('id')})
employee.connections = get_connections(employee.id)
2021-06-20 07:12:06 +00:00
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)
return num_connections