[IMP] hr_holidays: compute leave description based on user group
The leave description is now replaced with a compute method in order to obfuscate the description based on the user's group. closes odoo/odoo#38995 Taskid: 2088559 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
committed by
Yannick Tivisse
parent
db8904b03d
commit
eb02e9b3e0
@@ -18,6 +18,7 @@ from odoo.exceptions import AccessError, UserError, ValidationError
|
|||||||
from odoo.tools import float_compare
|
from odoo.tools import float_compare
|
||||||
from odoo.tools.float_utils import float_round
|
from odoo.tools.float_utils import float_round
|
||||||
from odoo.tools.translate import _
|
from odoo.tools.translate import _
|
||||||
|
from odoo.osv import expression
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -101,7 +102,8 @@ class HolidaysRequest(models.Model):
|
|||||||
return new_values
|
return new_values
|
||||||
|
|
||||||
# description
|
# description
|
||||||
name = fields.Char('Description')
|
name = fields.Char('Description', compute='_compute_description', inverse='_inverse_description', search='_search_description', compute_sudo=False)
|
||||||
|
private_name = fields.Char('Time Off Description', groups='hr_holidays.group_hr_holidays_user')
|
||||||
state = fields.Selection([
|
state = fields.Selection([
|
||||||
('draft', 'To Submit'),
|
('draft', 'To Submit'),
|
||||||
('cancel', 'Cancelled'),
|
('cancel', 'Cancelled'),
|
||||||
@@ -261,6 +263,36 @@ class HolidaysRequest(models.Model):
|
|||||||
self._table, ['date_to', 'date_from'])
|
self._table, ['date_to', 'date_from'])
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@api.depends_context('uid')
|
||||||
|
def _compute_description(self):
|
||||||
|
self.check_access_rights('read')
|
||||||
|
self.check_access_rule('read')
|
||||||
|
|
||||||
|
is_officer = self.user_has_groups('hr_holidays.group_hr_holidays_user')
|
||||||
|
|
||||||
|
for leave in self:
|
||||||
|
if is_officer or leave.user_id == self.env.user or leave.manager_id == self.env.user:
|
||||||
|
leave.name = leave.sudo().private_name
|
||||||
|
else:
|
||||||
|
leave.name = '*****'
|
||||||
|
|
||||||
|
def _inverse_description(self):
|
||||||
|
is_officer = self.user_has_groups('hr_holidays.group_hr_holidays_user')
|
||||||
|
|
||||||
|
for leave in self:
|
||||||
|
if is_officer or leave.user_id == self.env.user or leave.manager_id == self.env.user:
|
||||||
|
leave.sudo().private_name = leave.name
|
||||||
|
|
||||||
|
def _search_description(self, operator, value):
|
||||||
|
is_officer = self.user_has_groups('hr_holidays.group_hr_holidays_user')
|
||||||
|
domain = [('private_name', operator, value)]
|
||||||
|
|
||||||
|
if not is_officer:
|
||||||
|
domain = expression.AND([domain, [('user_id', '=', self.env.user.id)]])
|
||||||
|
|
||||||
|
leaves = self.search(domain)
|
||||||
|
return [('id', 'in', leaves.ids)]
|
||||||
|
|
||||||
@api.onchange('holiday_status_id')
|
@api.onchange('holiday_status_id')
|
||||||
def _onchange_holiday_status_id(self):
|
def _onchange_holiday_status_id(self):
|
||||||
self.request_unit_half = False
|
self.request_unit_half = False
|
||||||
@@ -618,26 +650,8 @@ class HolidaysRequest(models.Model):
|
|||||||
holiday_sudo.activity_update()
|
holiday_sudo.activity_update()
|
||||||
return holiday
|
return holiday
|
||||||
|
|
||||||
def _read(self, fields):
|
|
||||||
if 'name' in fields and 'employee_id' not in fields:
|
|
||||||
fields.add('employee_id')
|
|
||||||
super(HolidaysRequest, self)._read(fields)
|
|
||||||
if 'name' in fields:
|
|
||||||
if self.user_has_groups('hr_holidays.group_hr_holidays_user'):
|
|
||||||
return
|
|
||||||
current_employee = self.env['hr.employee'].sudo().search([('user_id', '=', self.env.uid)], limit=1)
|
|
||||||
for record in self:
|
|
||||||
emp_id = record._cache.get('employee_id') or False
|
|
||||||
if emp_id != current_employee.id:
|
|
||||||
try:
|
|
||||||
record._cache['name']
|
|
||||||
record._cache['name'] = '*****'
|
|
||||||
except Exception:
|
|
||||||
# skip SpecialValue (e.g. for missing record or access right)
|
|
||||||
pass
|
|
||||||
|
|
||||||
def write(self, values):
|
def write(self, values):
|
||||||
is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user')
|
is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user') or self.env.is_superuser()
|
||||||
|
|
||||||
if not is_officer:
|
if not is_officer:
|
||||||
if any(hol.date_from.date() < fields.Date.today() for hol in self):
|
if any(hol.date_from.date() < fields.Date.today() for hol in self):
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class LeaveReport(models.Model):
|
|||||||
from hr_leave_allocation as allocation
|
from hr_leave_allocation as allocation
|
||||||
union all select
|
union all select
|
||||||
request.employee_id as employee_id,
|
request.employee_id as employee_id,
|
||||||
request.name as name,
|
request.private_name as name,
|
||||||
(request.number_of_days * -1) as number_of_days,
|
(request.number_of_days * -1) as number_of_days,
|
||||||
request.category_id as category_id,
|
request.category_id as category_id,
|
||||||
request.department_id as department_id,
|
request.department_id as department_id,
|
||||||
|
|||||||
@@ -78,7 +78,6 @@
|
|||||||
domain="[('activity_ids.date_deadline', '>', context_today().strftime('%Y-%m-%d'))
|
domain="[('activity_ids.date_deadline', '>', context_today().strftime('%Y-%m-%d'))
|
||||||
]"/>
|
]"/>
|
||||||
<group expand="0" string="Group By">
|
<group expand="0" string="Group By">
|
||||||
<filter name="group_name" string="Description" context="{'group_by':'name'}"/>
|
|
||||||
<filter name="group_employee" string="Employee" context="{'group_by':'employee_id'}"/>
|
<filter name="group_employee" string="Employee" context="{'group_by':'employee_id'}"/>
|
||||||
<filter name="group_category" string="Category" context="{'group_by':'category_id'}"/>
|
<filter name="group_category" string="Category" context="{'group_by':'category_id'}"/>
|
||||||
<filter name="group_second_approver_id" string="Validator" context="{'group_by':'second_approver_id'}"/>
|
<filter name="group_second_approver_id" string="Validator" context="{'group_by':'second_approver_id'}"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user