[IMP] hr_holidays: add a leave request without validation mechanism

Purpose
=======

Allow to create a leave type for which leaves are not required to be approved
by a manager.

When a leave is created, it is automatically approved if the
validation type is set to "No validation".

It is useful if a manager does not need to manually approve some leave types.

Specification
=============

Add a validation type option for 'hr.leave.request': 'no_validation'

Automatically approve the leave when created and add the approver as follower
so that he can be notified about the leave creation/validation.

closes odoo/odoo#28268
This commit is contained in:
lul-odoo
2018-11-23 10:49:25 +00:00
committed by Yannick Tivisse
parent 7a0243ec15
commit c370f644a2
2 changed files with 13 additions and 3 deletions
+9
View File
@@ -471,6 +471,11 @@ class HolidaysRequest(models.Model):
def create(self, values):
""" Override to avoid automatic logging of creation """
employee_id = values.get('employee_id', False)
leave_type_id = values.get('holiday_status_id')
leave_type = self.env['hr.leave.type'].browse(leave_type_id)
if leave_type.validation_type == 'no_validation':
values.update({'state': 'confirm'})
if not values.get('department_id'):
values.update({'department_id': self.env['hr.employee'].browse(employee_id).department_id.id})
holiday = super(HolidaysRequest, self.with_context(mail_create_nolog=True, mail_create_nosubscribe=True)).create(values)
@@ -479,6 +484,10 @@ class HolidaysRequest(models.Model):
holiday._onchange_employee_id()
if 'number_of_days' not in values and ('date_from' in values or 'date_to' in values):
holiday._onchange_leave_dates()
if leave_type.validation_type == 'no_validation':
holiday.sudo().action_validate()
holiday.message_subscribe(partner_ids=[holiday._get_responsible_for_approval().partner_id.id])
holiday.sudo().message_post(body=_("The leave has been automatically approved"), subtype="mt_comment") # Message from OdooBot (sudo)
holiday.activity_update()
return holiday
+4 -3
View File
@@ -63,9 +63,10 @@ class HolidaysType(models.Model):
compute='_compute_group_days_leave', string='Group Leaves')
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.user.company_id)
validation_type = fields.Selection([
('hr', 'Human Resource officer'),
('manager', 'Employee Manager'),
('both', 'Double Validation')], default='hr', string='Validation By')
('no_validation', 'No Validation'),
('hr', 'Payroll Officer'),
('manager', 'Team Leader'),
('both', 'Team Leader and Payroll Officer')], default='hr', string='Validation By')
allocation_type = fields.Selection([
('fixed', 'Fixed by HR'),
('fixed_allocation', 'Fixed by HR + allocation request'),