示例#1
0
    def create_absence(self, absence: Absence) -> Absence:
        """
        Creates an absence record on the Personio servers

        :param absence: The absence object to be created
        :raises PersonioError: If the absence could not be created on the Personio servers
        """
        data = absence.to_body_params()
        response = self.request_json('company/time-offs', method='POST', data=data)
        if response['success']:
            absence.id_ = response['data']['attributes']['id']
            return absence
        raise PersonioError("Could not create absence")
示例#2
0
    def create_absence(self, absence: Absence) -> bool:
        """
        Creates an absence record on the Personio servers

        :param absence: The absence object to be created
        """
        data = absence.to_body_params()
        response = self.request_json('company/time-offs',
                                     method='POST',
                                     data=data)
        if response['success']:
            absence.id_ = response['data']['attributes']['id']
            return True
        return False
示例#3
0
    def __add_remote_absence_id(self, absence: Absence) -> Absence:
        """
        Queries the API for an absence record matching
        the given Absence object and adds the remote id.

        :param absence: The absence object to be updated
        :return: The absence object with the absence_id set
        """
        if absence.employee is None:
            raise ValueError("For a remote query an employee_id is required")
        if absence.start_date is None:
            raise ValueError("For a remote query a start date is required")
        if absence.end_date is None:
            raise ValueError("For a remote query an end date is required")
        matching_remote_absences = self.get_absences(employees=[absence.employee.id_],
                                                     start_date=absence.start_date,
                                                     end_date=absence.end_date)
        if len(matching_remote_absences) == 0:
            raise PersonioError("The absence to patch was not found")
        elif len(matching_remote_absences) > 1:
            raise PersonioError("More than one absence found.")
        absence.id_ = matching_remote_absences[0].id_
        return absence