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
  • requires_allocation
  • hide_on_dashboard
  • active
  • unit_of_measure
  • date_from
  • date_to
  • resource_calendar_id
  • resource_calendar_id.hours_per_day
  • number_of_days
current_date = date.today()
allocations = self.env['hr.leave.allocation'].search([('employee_id', 'in', self.ids)])
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 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
                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][work_entry_type][allocation][f'{primary_unit}_virtual_remaining_leaves']
                        employee_remaining_leaves += virtual_remaining_leaves\
                            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)

Back to entity