|
|
current_date = date.today()
data = self.env['hr.leave.allocation']._read_group([
('employee_id', 'in', self.ids),
('work_entry_type_id.active', '=', True),
('work_entry_type_id.requires_allocation', '=', True),
('state', '=', 'validate'),
('date_from', '<=', current_date),
'|',
('date_to', '=', False),
('date_to', '>=', current_date),
], ['employee_id'], ['__count', 'number_of_days:sum'])
rg_results = {employee.id: (count, days) for employee, count, days in data}
for employee in self:
count, days = rg_results.get(employee.id, (0, 0))
employee.allocation_count = float_round(days, precision_digits=2)
employee.allocations_count = count
|
|