mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-24 10:12:06 +02:00
19.0 vanilla
This commit is contained in:
parent
a1137a1456
commit
e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions
|
|
@ -4,15 +4,16 @@
|
|||
from odoo import fields, models
|
||||
|
||||
|
||||
class Employee(models.Model):
|
||||
_inherit = ["hr.employee"]
|
||||
class HrEmployee(models.Model):
|
||||
_inherit = "hr.employee"
|
||||
|
||||
subordinate_ids = fields.One2many('hr.employee', string='Subordinates', compute='_compute_subordinates', help="Direct and indirect subordinates",
|
||||
compute_sudo=True)
|
||||
is_subordinate = fields.Boolean(compute="_compute_is_subordinate", search="_search_is_subordinate")
|
||||
|
||||
|
||||
class HrEmployeePublic(models.Model):
|
||||
_inherit = ["hr.employee.public"]
|
||||
_inherit = "hr.employee.public"
|
||||
|
||||
subordinate_ids = fields.One2many('hr.employee.public', string='Subordinates', compute='_compute_subordinates', help="Direct and indirect subordinates",
|
||||
compute_sudo=True)
|
||||
subordinate_ids = fields.One2many(related='employee_id.subordinate_ids', compute_sudo=True)
|
||||
is_subordinate = fields.Boolean(related='employee_id.is_subordinate')
|
||||
|
|
|
|||
|
|
@ -1,16 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class HrEmployeeBase(models.AbstractModel):
|
||||
_inherit = "hr.employee.base"
|
||||
class HrEmployee(models.Model):
|
||||
_inherit = "hr.employee"
|
||||
|
||||
child_all_count = fields.Integer(
|
||||
'Indirect Subordinates Count',
|
||||
compute='_compute_subordinates', recursive=True, store=False,
|
||||
compute_sudo=True)
|
||||
department_color = fields.Integer("Department Color", related="department_id.color")
|
||||
child_count = fields.Integer(
|
||||
'Direct Subordinates Count',
|
||||
compute='_compute_child_count', recursive=True,
|
||||
compute_sudo=True,
|
||||
)
|
||||
|
||||
def _get_subordinates(self, parents=None):
|
||||
"""
|
||||
|
|
@ -30,9 +37,51 @@ class HrEmployeeBase(models.AbstractModel):
|
|||
indirect_subordinates |= child_subordinates
|
||||
return indirect_subordinates | direct_subordinates
|
||||
|
||||
|
||||
@api.depends('child_ids', 'child_ids.child_all_count')
|
||||
def _compute_subordinates(self):
|
||||
for employee in self:
|
||||
employee.subordinate_ids = employee._get_subordinates()
|
||||
employee.child_all_count = len(employee.subordinate_ids)
|
||||
|
||||
@api.depends_context('uid', 'company')
|
||||
@api.depends('parent_id')
|
||||
def _compute_is_subordinate(self):
|
||||
subordinates = self.env.user.employee_id.subordinate_ids
|
||||
if not subordinates:
|
||||
self.is_subordinate = False
|
||||
else:
|
||||
for employee in self:
|
||||
employee.is_subordinate = employee in subordinates
|
||||
|
||||
def _search_is_subordinate(self, operator, value):
|
||||
if operator != 'in':
|
||||
return NotImplemented
|
||||
subordinates = self.env.user.employee_id.subordinate_ids
|
||||
return [('id', 'in', subordinates.ids)]
|
||||
|
||||
def _compute_child_count(self):
|
||||
employee_read_group = self._read_group(
|
||||
[('parent_id', 'in', self.ids)],
|
||||
['parent_id'],
|
||||
['id:count'],
|
||||
)
|
||||
child_count_per_parent_id = dict(employee_read_group)
|
||||
for employee in self:
|
||||
employee.child_count = child_count_per_parent_id.get(employee._origin, 0)
|
||||
|
||||
|
||||
class HrEmployeePublic(models.Model):
|
||||
_inherit = "hr.employee.public"
|
||||
|
||||
child_all_count = fields.Integer(compute='_compute_child_all_count')
|
||||
department_color = fields.Integer(compute='_compute_department_color')
|
||||
child_count = fields.Integer(compute='_compute_child_count')
|
||||
|
||||
def _compute_child_all_count(self):
|
||||
self._compute_from_employee('child_all_count')
|
||||
|
||||
def _compute_department_color(self):
|
||||
self._compute_from_employee('department_color')
|
||||
|
||||
def _compute_child_count(self):
|
||||
self._compute_from_employee('child_count')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue