parameters: (self, state)
docstring: Check if target state is achievable.
docstring_summary: Check if target state is achievable.
docstring_tokens: Check if target state is achievable .
function: def _check_approval_update(self, state):
          """ Check if target state is achievable. """
          if self.env.is_superuser():
              return
          current_employee = self.env.user.employee_id
          if not current_employee:
              return
          is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user')
          is_manager = self.env.user.has_group('hr_holidays.group_hr_holidays_manager')
          for holiday in self:
              val_type = holiday.holiday_status_id.sudo().allocation_validation_type
              if state == 'confirm':
                  continue
  
              if state == 'draft':
                  if holiday.employee_id != current_employee and not is_manager:
                      raise UserError(_('Only a time off Manager can reset other people allocation.'))
                  continue
  
              if not is_officer and self.env.user != holiday.employee_id.leave_manager_id and not val_type == 'no':
                  raise UserError(_('Only a time off Officer/Responsible or Manager can approve or refuse time off requests.'))
  
              if is_officer or self.env.user == holiday.employee_id.leave_manager_id:
                  # use ir.rule based first access check: department, members, ... (see security.xml)
                  holiday.check_access_rule('write')
  
              if holiday.employee_id == current_employee and not is_manager and not val_type == 'no':
                  raise UserError(_('Only a time off Manager can approve its own requests.'))
  
              if (state == 'validate1' and val_type == 'both') or (state == 'validate' and val_type == 'manager'):
                  if self.env.user == holiday.employee_id.leave_manager_id and self.env.user != holiday.employee_id.user_id:
                      continue
                  manager = holiday.employee_id.parent_id or holiday.employee_id.department_id.manager_id
                  if (manager != current_employee) and not is_manager:
                      raise UserError(_('You must be either %s\'s manager or time off manager to approve this time off') % (holiday.employee_id.name))
  
              if state == 'validate' and val_type == 'both':
                  if not is_officer:
                      raise UserError(_('Only a Time off Approver can apply the second approval on allocation requests.'))
function_tokens: def _check_approval_update ( self , state ) : if self . env . is_superuser ( ) : return current_employee = self . env . user . employee_id if not current_employee : return is_officer = self . env . user . has_group ( 'hr_holidays.group_hr_holidays_user' ) is_manager = self . env . user . has_group ( 'hr_holidays.group_hr_holidays_manager' ) for holiday in self : val_type = holiday . holiday_status_id . sudo ( ) . allocation_validation_type if state == 'confirm' : continue if state == 'draft' : if holiday . employee_id != current_employee and not is_manager : raise UserError ( _ ( 'Only a time off Manager can reset other people allocation.' ) ) continue if not is_officer and self . env . user != holiday . employee_id . leave_manager_id and not val_type == 'no' : raise UserError ( _ ( 'Only a time off Officer/Responsible or Manager can approve or refuse time off requests.' ) ) if is_officer or self . env . user == holiday . employee_id . leave_manager_id : # use ir.rule based first access check: department, members, ... (see security.xml) holiday . check_access_rule ( 'write' ) if holiday . employee_id == current_employee and not is_manager and not val_type == 'no' : raise UserError ( _ ( 'Only a time off Manager can approve its own requests.' ) ) if ( state == 'validate1' and val_type == 'both' ) or ( state == 'validate' and val_type == 'manager' ) : if self . env . user == holiday . employee_id . leave_manager_id and self . env . user != holiday . employee_id . user_id : continue manager = holiday . employee_id . parent_id or holiday . employee_id . department_id . manager_id if ( manager != current_employee ) and not is_manager : raise UserError ( _ ( 'You must be either %s\'s manager or time off manager to approve this time off' ) % ( holiday . employee_id . name ) ) if state == 'validate' and val_type == 'both' : if not is_officer : raise UserError ( _ ( 'Only a Time off Approver can apply the second approval on allocation requests.' ) )