Skip to content

Commit c934652

Browse files
author
Philippe Wauthy
committed
[IMP] hr_holidays: set time off default employee when created from allocation smart button
In hr_holidays, each allocation granted to an employee has a smart button to see the linked time off for this employee. The create button on the tree view that shows these time off opens the form with self.env.user.employee_id as default employee. This commit changes the default employee of the time off to be the one of the original allocation task-2844554 closes odoo#90739 Signed-off-by: Kevin Baptiste <kba@odoo.com>
1 parent 12107a4 commit c934652

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

addons/hr_holidays/models/hr_leave.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,20 @@ def _compute_from_employee_ids(self):
457457

458458
@api.depends('holiday_type')
459459
def _compute_from_holiday_type(self):
460+
allocation_from_domain = self.env['hr.leave.allocation']
461+
if (self._context.get('active_model') == 'hr.leave.allocation' and
462+
self._context.get('active_id')):
463+
allocation_from_domain = allocation_from_domain.browse(self._context['active_id'])
460464
for holiday in self:
461465
if holiday.holiday_type == 'employee':
462466
if not holiday.employee_ids:
463-
# This handles the case where a request is made with only the employee_id
464-
# but does not need to be recomputed on employee_id changes
465-
holiday.employee_ids = holiday.employee_id or self.env.user.employee_id
467+
if allocation_from_domain:
468+
holiday.employee_ids = allocation_from_domain.employee_id
469+
holiday.holiday_status_id = allocation_from_domain.holiday_status_id
470+
else:
471+
# This handles the case where a request is made with only the employee_id
472+
# but does not need to be recomputed on employee_id changes
473+
holiday.employee_ids = holiday.employee_id or self.env.user.employee_id
466474
holiday.mode_company_id = False
467475
holiday.category_id = False
468476
elif holiday.holiday_type == 'company':

addons/hr_holidays/models/hr_leave_type.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ def _compute_accrual_count(self):
397397
@api.depends('employee_requests')
398398
def _compute_allocation_validation_type(self):
399399
for leave_type in self:
400-
leave_type.allocation_validation_type = 'no' if leave_type.employee_requests == 'no' else 'officer'
400+
if leave_type.employee_requests == 'no':
401+
leave_type.allocation_validation_type = 'officer'
401402

402403
def requested_name_get(self):
403404
return self._context.get('holiday_status_name_get', True) and self._context.get('employee_id')

0 commit comments

Comments
 (0)