Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.
Module: Time Off
Entity: hr.employee
Compute Method: _compute_allocation_remaining_display
| Inputs | Method | Outputs |
|---|---|---|
|
current_date = date.today()
allocations = self.env['hr.leave.allocation'].search([('employee_id', 'in', self.ids)])
- leaves_taken = self._get_consumed_leaves(allocations.holiday_status_id)[0]
+ leaves_taken = self._get_consumed_leaves(allocations.work_entry_type_id)[0]
for employee in self:
employee_remaining_leaves = 0
employee_max_leaves = 0
- for leave_type in leaves_taken[employee]:
- if leave_type.requires_allocation == 'no' or leave_type.hide_on_dashboard or not leave_type.active:
+ for work_entry_type in leaves_taken[employee]:
+ if not work_entry_type.requires_allocation or work_entry_type.hide_on_dashboard or not work_entry_type.active:
continue
- for allocation in leaves_taken[employee][leave_type]:
+ primary_unit = 'hours' if work_entry_type.unit_of_measure == 'hour' else 'days'
+ for allocation in leaves_taken[employee][work_entry_type]:
if allocation and allocation.date_from <= current_date\
and (not allocation.date_to or allocation.date_to >= current_date):
- virtual_remaining_leaves = leaves_taken[employee][leave_type][allocation]['virtual_remaining_leaves']
+ virtual_remaining_leaves = leaves_taken[employee][work_entry_type][allocation][f'{primary_unit}_virtual_remaining_leaves']
employee_remaining_leaves += virtual_remaining_leaves\
- if leave_type.request_unit in ['day', 'half_day']\
+ if work_entry_type.unit_of_measure == 'day'\
else virtual_remaining_leaves / (employee.resource_calendar_id.hours_per_day or HOURS_PER_DAY)
employee_max_leaves += allocation.number_of_days
employee.allocation_remaining_display = "%g" % float_round(employee_remaining_leaves, precision_digits=2)
employee.allocation_display = "%g" % float_round(employee_max_leaves, precision_digits=2)
|
|
