[FIX] hr_holidays: always make leave type visible to holiday manager

A holiday manager should always see the leave types whatever the value
of employee_applicability is.
This commit is contained in:
RomainLibert
2018-06-19 11:15:07 +02:00
parent 50860317cc
commit 0f02aed0be
2 changed files with 14 additions and 4 deletions
+7 -2
View File
@@ -38,12 +38,17 @@ class HolidaysRequest(models.Model):
_order = "date_from desc"
_inherit = ['mail.thread', 'mail.activity.mixin']
def _default_domain_holiday_status(self):
if self.user_has_groups('hr_holidays.group_hr_holidays_manager'):
return [('valid', '=', True)]
return [('valid', '=', True), ('employee_applicability', 'in', ['leave', 'both'])]
@api.model
def default_get(self, fields_list):
defaults = super(HolidaysRequest, self).default_get(fields_list)
LeaveType = self.env['hr.leave.type'].with_context(employee_id=defaults.get('employee_id'), default_date_from=defaults.get('date_from'))
lt = LeaveType.search([('valid', '=', True), ('employee_applicability', 'in', ['leave', 'both'])])
lt = LeaveType.search(self._default_domain_holiday_status())
defaults['holiday_status_id'] = lt[0].id if len(lt) > 0 else defaults.get('holiday_status_id')
return defaults
@@ -75,7 +80,7 @@ class HolidaysRequest(models.Model):
states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, track_visibility='onchange')
holiday_status_id = fields.Many2one("hr.leave.type", string="Leave Type", required=True, readonly=True,
states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]},
domain="[('valid', '=', True), ('employee_applicability', 'in', ['leave', 'both'])]")
domain=lambda self: self._default_domain_holiday_status())
employee_id = fields.Many2one('hr.employee', string='Employee', index=True, readonly=True,
states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, default=_default_employee, track_visibility='onchange')
manager_id = fields.Many2one('hr.employee', string='Manager', readonly=True)
@@ -33,12 +33,17 @@ class HolidaysAllocation(models.Model):
_description = "Leaves Allocation"
_inherit = ['mail.thread', 'mail.activity.mixin']
def _default_domain_holiday_status_id(self):
if self.user_has_groups('hr_holidays.group_hr_holidays_manager'):
return [('valid', '=', True), ('limit', '=', False)]
return [('valid', '=', True), ('employee_applicability', 'in', ['allocation', 'both']), ('limit', '=', False)]
def _default_employee(self):
return self.env.context.get('default_employee_id') or self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)
def _default_holiday_status_id(self):
LeaveType = self.env['hr.leave.type'].with_context(employee_id=self._default_employee().id)
lt = LeaveType.search([('valid', '=', True), ('employee_applicability', 'in', ['leave', 'both']), ('limit', '=', False)])
lt = LeaveType.search(self._default_domain_holiday_status_id())
return lt[:1]
name = fields.Char('Description')
@@ -56,7 +61,7 @@ class HolidaysAllocation(models.Model):
"\nThe status is 'Approved', when leave request is approved by manager.")
holiday_status_id = fields.Many2one("hr.leave.type", string="Leave Type", required=True, readonly=True,
states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]},
domain="[('valid', '=', True), ('employee_applicability', 'in', ['allocation', 'both']), ('limit', '=', False)]", default=_default_holiday_status_id)
domain=lambda self: self._default_domain_holiday_status_id(), default=_default_holiday_status_id)
employee_id = fields.Many2one('hr.employee', string='Employee', index=True, readonly=True,
states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, default=_default_employee, track_visibility='onchange')
notes = fields.Text('Reasons', readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]})