diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 20a878dc0a2..d1c365fd36a 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -13,6 +13,7 @@ from odoo.addons.resource.models.resource import HOURS_PER_DAY from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools.translate import _ from odoo.tools.float_utils import float_round +from odoo.osv import expression _logger = logging.getLogger(__name__) @@ -40,7 +41,8 @@ class HolidaysAllocation(models.Model): return [('valid', '=', True), ('allocation_type', '!=', 'no')] return [('valid', '=', True), ('allocation_type', '=', 'fixed_allocation')] - name = fields.Char('Description') + name = fields.Char('Description', compute='_compute_description', inverse='_inverse_description', search='_search_description', compute_sudo=False) + private_name = fields.Char('Allocation Description', groups='hr_holidays.group_hr_holidays_user') state = fields.Selection([ ('draft', 'To Submit'), ('cancel', 'Cancelled'), @@ -208,6 +210,35 @@ class HolidaysAllocation(models.Model): holiday.write(values) + @api.depends_context('uid') + def _compute_description(self): + self.check_access_rights('read') + self.check_access_rule('read') + + is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user') + + for allocation in self: + if is_officer or allocation.employee_id.user_id == self.env.user or allocation.manager_id == self.env.user: + allocation.name = allocation.sudo().private_name + else: + allocation.name = '*****' + + def _inverse_description(self): + is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user') + for allocation in self: + if is_officer or allocation.employee_id.user_id == self.env.user or allocation.manager_id == self.env.user: + allocation.sudo().private_name = allocation.name + + def _search_description(self, operator, value): + is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user') + domain = [('private_name', operator, value)] + + if not is_officer: + domain = expression.AND([domain, [('employee_id.user_id', '=', self.env.user.id)]]) + + allocations = self.sudo().search(domain) + return [('id', 'in', allocations.ids)] + @api.depends('employee_id', 'holiday_status_id') def _compute_leaves(self): for allocation in self: diff --git a/addons/hr_holidays/report/hr_leave_report.py b/addons/hr_holidays/report/hr_leave_report.py index c6bf97722fd..80f2b189260 100644 --- a/addons/hr_holidays/report/hr_leave_report.py +++ b/addons/hr_holidays/report/hr_leave_report.py @@ -51,7 +51,7 @@ class LeaveReport(models.Model): leaves.date_to as date_to, leaves.payslip_status as payslip_status from (select allocation.employee_id as employee_id, - allocation.name as name, + allocation.private_name as name, allocation.number_of_days as number_of_days, allocation.category_id as category_id, allocation.department_id as department_id,