In hr_holidays_attendance, the model that inherits from res.users adds a request_overtime field. This field is used to allow the user to request overtime based on the total overtime. The domain for the time off type includes has_valid_allocation. If the user doesn't have any allocation, he won't be able to deduct extra hours task-2701128 closes odoo/odoo#87845 X-original-commit: b6d186d7b46df1e0f4e0af3eb7c8e7b07909a040 Related: odoo/enterprise#25843 Signed-off-by: Kevin Baptiste <kba@odoo.com>
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class ResUsers(models.Model):
|
|
_inherit = 'res.users'
|
|
|
|
request_overtime = fields.Boolean(compute='_compute_request_overtime')
|
|
|
|
@property
|
|
def SELF_READABLE_FIELDS(self):
|
|
return super().SELF_READABLE_FIELDS + ['request_overtime']
|
|
|
|
@api.depends_context('uid')
|
|
@api.depends('total_overtime')
|
|
def _compute_request_overtime(self):
|
|
is_holiday_user = self.env.user.has_group('hr_holidays.group_hr_holidays_user')
|
|
time_off_types = self.env['hr.leave.type'].search_count([
|
|
('requires_allocation', '=', 'yes'),
|
|
('employee_requests', '=', 'yes'),
|
|
('overtime_deductible', '=', True)
|
|
])
|
|
for user in self:
|
|
if user.total_overtime >= 1:
|
|
if is_holiday_user:
|
|
user.request_overtime = True
|
|
else:
|
|
user.request_overtime = time_off_types
|
|
else:
|
|
user.request_overtime = False
|