i have this function to make 'holiday_status_id' field dynamic domain
it works fine but only with CREATE button
how can i make it available all time
@api.model
@api.onchange('employee_id', 'type', 'state','holiday_status_id')
def change_leave_type(self):
for holiday_type in self:
if holiday_type.type == 'add':
if holiday_type.state in ['draft', 'confirm', 'validate', 'validate1']:
if holiday_type.type == 'add' and holiday_type.env.uid == holiday_type.user_id.id and not holiday_type.env.user.has_group(
'hr_holidays.group_hr_holidays_user'):
allocate_type = holiday_type.env['hr.holidays.status'].search(
[('name', '=', 'Compensatory Days')]).id
return {'domain': {'holiday_status_id': [('id', '=', allocate_type)]}}
elif holiday_type.type == 'add' and holiday_type.env.user.has_group(
'hr_holidays.group_hr_holidays_user') and not holiday_type.env.user.has_group(
'hr_holidays.group_hr_holidays_manager'):
ids = []
allocation_types = holiday_type.env['hr.holidays.status'].search([])
for allocate in allocation_types:
if allocate.name != 'Unpaid':
ids.append(allocate.id)
return {'domain': {'holiday_status_id': [('id', '=', ids)]}}