From 1ca3b3df3421961caec3b747a364071c80f5c7da Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 17:14:58 +0700 Subject: initial commit --- hr_organizational_chart/controller/__init__.py | 24 +++++ hr_organizational_chart/controller/main.py | 129 +++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 hr_organizational_chart/controller/__init__.py create mode 100644 hr_organizational_chart/controller/main.py (limited to 'hr_organizational_chart/controller') diff --git a/hr_organizational_chart/controller/__init__.py b/hr_organizational_chart/controller/__init__.py new file mode 100644 index 0000000..e406867 --- /dev/null +++ b/hr_organizational_chart/controller/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +################################################################################### +# A part of OpenHRMS Project +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2018-TODAY Cybrosys Technologies (). +# Author: Cybrosys Technologies () +# +# This program is free software: you can modify +# it under the terms of the GNU Affero General Public License (AGPL) as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +from . import main \ No newline at end of file diff --git a/hr_organizational_chart/controller/main.py b/hr_organizational_chart/controller/main.py new file mode 100644 index 0000000..71efb1a --- /dev/null +++ b/hr_organizational_chart/controller/main.py @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- +################################################################################### +# A part of OpenHRMS Project +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2018-TODAY Cybrosys Technologies (). +# Author: Cybrosys Technologies () +# +# This program is free software: you can modify +# it under the terms of the GNU Affero General Public License (AGPL) as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +from odoo import http +from odoo.exceptions import UserError +from odoo.http import request + + +class EmployeeChart(http.Controller): + + @http.route('/get/parent/colspan', type='json', auth='public', method=['POST'], csrf=False) + def get_col_span(self, emp_id): + if emp_id: + employee = request.env['hr.employee'].sudo().browse(int(emp_id)) + if employee.child_ids: + child_count = len(employee.child_ids) * 2 + return child_count + + @http.route('/get/parent/employee', type='json', auth='public', method=['POST'], csrf=False) + def get_employee_ids(self): + employees = request.env['hr.employee'].sudo().search([('parent_id', '=', False)]) + names = [] + key = [] + if len(employees) == 1: + key.append(employees.id) + key.append(len(employees.child_ids)) + return key + elif len(employees) == 0: + raise UserError( + "Should not have manager for the employee in the top of the chart") + else: + for emp in employees: + names.append(emp.name) + raise UserError( + "These employee have no Manager %s" % (names)) + + def get_lines(self, loop_count): + if loop_count: + lines = """ +
""" + for i in range(0, loop_count): + if i % 2 == 0: + if i == 0: + lines += """""" + else: + lines += """""" + else: + if i == loop_count-1: + lines += """""" + else: + lines += """""" + lines += """""" + return lines + + def get_nodes(self, child_ids): + if child_ids: + child_nodes = """""" + for child in child_ids: + child_table = """ +
""" + view = """ """ + child_nodes += child_table + view + """
""" + nodes = child_nodes + """""" + return nodes + + @http.route('/get/parent/child', type='http', auth='user', method=['POST'], csrf=False) + def get_parent_child(self, **post): + if post: + val = 0 + for line in post: + if line: + val = int(line) + child_ids = request.env['hr.employee'].sudo().browse(val).child_ids + emp = request.env['hr.employee'].sudo().browse(val) + table = """""" + loop_len = len(child_ids)*2 + lines = self.get_lines(loop_len) + nodes = self.get_nodes(child_ids) + table += lines + nodes + return table + + @http.route('/get/child/data', type='json', auth='user', method=['POST'], csrf=False) + def get_child_data(self, click_id): + if click_id: + employee = request.env['hr.employee'].sudo().browse(int(click_id)) + if employee.child_ids: + child_count = len(employee.child_ids) * 2 + value = [child_count] + lines = self.get_lines(child_count) + nodes = self.get_nodes(employee.child_ids) + child_table = lines + nodes + value.append(child_table) + return child_table + + + + + + -- cgit v1.2.3