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.leave

Compute Method: _compute_leaves

Inputs Method Outputs
date_from = fields.Date.from_string(self.env.context['default_request_date_from']) if 'default_request_date_from' in self.env.context else fields.Date.context_today(self)
employee_days_per_allocation = self.employee_id._get_consumed_leaves(self.work_entry_type_id, date_from)[0]
for leave in self:
            virtual_remaining_leaves = 0
            max_leaves = 0
            primary_unit = 'hours' if leave.work_entry_type_id.unit_of_measure == 'hour' else 'days'
            for allocation, allocation_dict in employee_days_per_allocation[leave.employee_id][leave.work_entry_type_id].items():
                if allocation and (not allocation.date_to or allocation.date_to >= date_from):
                    max_leaves += allocation_dict[f'{primary_unit}_max_leaves']
                    virtual_remaining_leaves += allocation_dict[f'{primary_unit}_virtual_remaining_leaves']
            leave.virtual_remaining_leaves = virtual_remaining_leaves
            leave.max_leaves = max_leaves

Back to entity