Created
July 28, 2020 04:40
-
-
Save sehrishnaz/f00aaf70c1f5b21282406fed52734de3 to your computer and use it in GitHub Desktop.
Tree Data Structure for Manager Employee Hierarchy Server Action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HREmployee(models.Model): | |
| _inherit = 'hr.employee' | |
| @api.multi | |
| def load_employee_hierarchy(self): | |
| domain = [] | |
| if self._context.get('params', False): | |
| params = self._context.get('params', False) | |
| if params.get('menu_id', False): | |
| raise ValidationError( | |
| "Attention:You are not allowed to access this page due to Security Policy. In case of any query, please contact ERP Admin or Configuration Manager.") | |
| else: | |
| return False | |
| view_id_tree = self.env['ir.ui.view'].search([('name', '=', 'hr.employee.hierarchy.tree')]) | |
| user = self.env['res.users'].browse(self._uid) | |
| employee_pool = self.env['hr.employee'] | |
| employee = employee_pool.search([('user_id', '=', user.id)]) | |
| employee_ids = [] | |
| if user.has_group('your_module.your_group_name_1'): | |
| # show all employees | |
| employee_ids = self.env['hr.employee'].search([]).ids | |
| if user.has_group('your_module.your_group_name_2'): | |
| # show user company employee | |
| employee_ids += self.env['hr.employee'].search([('company_id', '=', user.company_id.id)]).ids | |
| if user.has_group('base.group_user'): | |
| # show own record | |
| employee_ids += employee.ids | |
| employee_ids = list(set(employee_ids) - set([1])) | |
| return { | |
| 'type': 'ir.actions.act_window', | |
| 'res_model': 'hr.employee', | |
| 'view_type': 'tree', | |
| 'view_mode': 'tree', | |
| 'view_id': view_id_tree.id, | |
| 'views': [(view_id_tree[0].id, 'tree')], | |
| 'target': 'current', | |
| 'domain': [('parent_id','=',False),('id','in',employee_ids)] | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For details: http://learnopenerp.blogspot.com/2020/07/create-organization-employee-hierarchy-tree-view-in-odoo.html