Exemplo n.º 1
0
class ShortEmployee(LabeledAttributesMixin):

    _api_type_name = "Employee"
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('first_name', 'first_name', str),
        FieldMapping('last_name', 'last_name', str),
        FieldMapping('email', 'email', str),
    ]

    def __init__(self,
                 client: 'Personio' = None,
                 id_: int = None,
                 first_name: str = None,
                 last_name: str = None,
                 email: str = None,
                 **kwargs):
        super().__init__(**kwargs)
        self._client = client
        self.id_ = id_
        self.first_name = first_name
        self.last_name = last_name
        self.email = email

    def resolve(self, client: 'Personio' = None) -> 'Employee':
        client = client or self._client
        if client:
            return client.get_employee(self.id_)
        else:
            raise PersonioError(
                f"no Personio client is is available in this {self.__class__.__name__} instance "
                f"to make a request for the full employee profile of "
                f"{self.first_name} {self.last_name} ({self.id_})")
Exemplo n.º 2
0
class Attendance(WritablePersonioResource):

    _api_type_name = "AttendancePeriod"
    _field_mapping_list = [
        # note: the id is actually not in the attributes dict, but one level higher
        NumericFieldMapping('id', 'id_', int),
        NumericFieldMapping('employee', 'employee_id', int),
        DateFieldMapping('date', 'date'),
        DurationFieldMapping('start_time', 'start_time'),
        DurationFieldMapping('end_time', 'end_time'),
        NumericFieldMapping('break', 'break_duration', int),
        FieldMapping('comment', 'comment', str),
        BooleanFieldMapping('is_holiday', 'is_holiday'),
        BooleanFieldMapping('is_on_time_off', 'is_on_time_off'),
    ]

    def __init__(self,
                 client: 'Personio' = None,
                 dynamic: Dict[str, Any] = None,
                 dynamic_raw: List['DynamicAttr'] = None,
                 id_: int = None,
                 employee_id: int = None,
                 date: datetime = None,
                 start_time: str = None,
                 end_time: str = None,
                 break_duration: int = None,
                 comment: str = None,
                 is_holiday: bool = None,
                 is_on_time_off: bool = None,
                 **kwargs):
        super().__init__(client=client,
                         dynamic=dynamic,
                         dynamic_raw=dynamic_raw,
                         **kwargs)
        self.id_ = id_
        self.employee_id = employee_id
        self.date = date
        self.start_time = start_time
        self.end_time = end_time
        self.break_duration = break_duration
        self.comment = comment
        self.is_holiday = is_holiday
        self.is_on_time_off = is_on_time_off

    def to_dict(self, nested=False) -> Dict[str, Any]:
        # yes, this is weird an unnecessary, but that's how the api works
        d = super().to_dict()
        d['id'] = self.id_
        del d['attributes']['id']
        return d

    def _create(self, client: 'Personio'):
        pass

    def _update(self, client: 'Personio'):
        pass

    def _delete(self, client: 'Personio'):
        pass
Exemplo n.º 3
0
class HolidayCalendar(PersonioResource):

    _api_type_name = 'HolidayCalendar'
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('name', 'name', str),
        FieldMapping('country', 'country', str),
        FieldMapping('state', 'state', str),
    ]

    def __init__(self, id_: int = None, name: str = None, country: str = None,
                 state: str = None, **kwargs):
        super().__init__(**kwargs)
        self.id_ = id_
        self.name = name
        self.country = country
        self.state = state
Exemplo n.º 4
0
class Certificate(PersonioResource):

    _field_mapping_list = [
        FieldMapping('status', 'status', str),
    ]
    _flat_dict = True

    def __init__(self, status: str = None, **kwargs):
        super().__init__(**kwargs)
        self.status = status
Exemplo n.º 5
0
class Team(PersonioResource):

    _api_type_name = 'Team'
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('name', 'name', str),
    ]

    def __init__(self, id_: int = None, name: str = None, **kwargs):
        super().__init__(**kwargs)
        self.id_ = id_
        self.name = name
Exemplo n.º 6
0
class CostCenter(PersonioResource):

    _api_type_name = 'CostCenter'
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('name', 'name', str),
        NumericFieldMapping('percentage', 'percentage', float),
    ]

    def __init__(self, id_: int = None, name: str = None, percentage: float = None, **kwargs):
        super().__init__(**kwargs)
        self.id_ = id_
        self.name = name
        self.percentage = percentage
Exemplo n.º 7
0
class AbsenceEntitlement(PersonioResource):

    _api_type_name = "TimeOffType"
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('name', 'name', str),
        NumericFieldMapping('entitlement', 'entitlement', float),
    ]

    def __init__(self, id_: int = None, name: str = None, entitlement: float = None, **kwargs):
        super().__init__(**kwargs)
        self.id_ = id_
        self.name = name
        self.entitlement = entitlement
Exemplo n.º 8
0
class AbsenceType(PersonioResource):

    _api_type_name = "TimeOffType"
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('name', 'name', str),
    ]

    def __init__(self, id_: int = None, name: str = None, **kwargs):
        super().__init__(**kwargs)
        self.id_ = id_
        self.name = name

    def to_dict(self, nested=False) -> Dict[str, Any]:
        if nested:
            return super().to_dict()
        else:
            return {
                'type': self._api_type_name,
                'attributes': super().to_dict(),
            }
Exemplo n.º 9
0
class WorkSchedule(PersonioResource):

    _api_type_name = 'WorkSchedule'
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('name', 'name', str),
        DateFieldMapping('valid_from', 'valid_from'),
        DurationFieldMapping('monday', 'monday'),
        DurationFieldMapping('tuesday', 'tuesday'),
        DurationFieldMapping('wednesday', 'wednesday'),
        DurationFieldMapping('thursday', 'thursday'),
        DurationFieldMapping('friday', 'friday'),
        DurationFieldMapping('saturday', 'saturday'),
        DurationFieldMapping('sunday', 'sunday'),
    ]

    def __init__(self,
                 id_: int = None,
                 name: str = None,
                 valid_from: datetime = None,
                 monday: timedelta = None,
                 tuesday: timedelta = None,
                 wednesday: timedelta = None,
                 thursday: timedelta = None,
                 friday: timedelta = None,
                 saturday: timedelta = None,
                 sunday: timedelta = None,
                 **kwargs):
        super().__init__(**kwargs)
        self.id_ = id_
        self.name = name
        self.valid_from = valid_from
        self.monday = monday
        self.tuesday = tuesday
        self.wednesday = wednesday
        self.thursday = thursday
        self.friday = friday
        self.saturday = saturday
        self.sunday = sunday
Exemplo n.º 10
0
class Employee(WritablePersonioResource, LabeledAttributesMixin):

    _api_type_name = "Employee"
    _can_delete = False
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('first_name', 'first_name', str),
        FieldMapping('last_name', 'last_name', str),
        FieldMapping('email', 'email', str),
        FieldMapping('gender', 'gender', str),
        FieldMapping('status', 'status', str),
        FieldMapping('position', 'position', str),
        ObjectFieldMapping('supervisor', 'supervisor', ShortEmployee),
        FieldMapping('employment_type', 'employment_type', str),
        FieldMapping('weekly_working_hours', 'weekly_working_hours', str),
        DateFieldMapping('hire_date', 'hire_date'),
        DateFieldMapping('contract_end_date', 'contract_end_date'),
        DateFieldMapping('termination_date', 'termination_date'),
        FieldMapping('termination_type', 'termination_type', str),
        FieldMapping('termination_reason', 'termination_reason', str),
        DateFieldMapping('probation_period_end', 'probation_period_end'),
        DateTimeFieldMapping('created_at', 'created_at'),
        DateTimeFieldMapping('last_modified_at', 'last_modified_at'),
        FieldMapping('subcompany', 'subcompany', str),
        ObjectFieldMapping('office', 'office', Office),
        ObjectFieldMapping('department', 'department', Department),
        ListFieldMapping(
            ObjectFieldMapping('cost_centers', 'cost_centers', CostCenter)),
        NumericFieldMapping('fix_salary', 'fix_salary', float),
        FieldMapping('fix_salary_interval', 'fix_salary_interval', str),
        NumericFieldMapping('hourly_salary', 'hourly_salary', float),
        NumericFieldMapping('vacation_day_balance', 'vacation_day_balance',
                            float),
        DateFieldMapping('last_working_day', 'last_working_day'),
        ObjectFieldMapping('holiday_calendar', 'holiday_calendar',
                           HolidayCalendar),
        ObjectFieldMapping('work_schedule', 'work_schedule', WorkSchedule),
        ListFieldMapping(
            ObjectFieldMapping('absence_entitlement', 'absence_entitlement',
                               AbsenceEntitlement)),
        FieldMapping('profile_picture', 'profile_picture', str),
        ObjectFieldMapping('team', 'team', Team),
    ]

    def __init__(self,
                 client: 'Personio' = None,
                 dynamic: Dict[str, Any] = None,
                 dynamic_raw: List['DynamicAttr'] = None,
                 id_: int = None,
                 first_name: str = None,
                 last_name: str = None,
                 email: str = None,
                 gender: str = None,
                 status: str = None,
                 position: str = None,
                 supervisor: ShortEmployee = None,
                 employment_type: str = None,
                 weekly_working_hours: str = None,
                 hire_date: datetime = None,
                 contract_end_date: datetime = None,
                 termination_date: datetime = None,
                 termination_type: str = None,
                 termination_reason: str = None,
                 probation_period_end: datetime = None,
                 created_at: datetime = None,
                 last_modified_at: datetime = None,
                 subcompany: str = None,
                 office: Office = None,
                 department: Department = None,
                 cost_centers: List[CostCenter] = None,
                 holiday_calendar: HolidayCalendar = None,
                 absence_entitlement: List[AbsenceEntitlement] = None,
                 work_schedule: WorkSchedule = None,
                 fix_salary: float = None,
                 fix_salary_interval: str = None,
                 hourly_salary: float = None,
                 vacation_day_balance: float = None,
                 last_working_day: datetime = None,
                 profile_picture: str = None,
                 team: Team = None,
                 **kwargs):
        super().__init__(client=client,
                         dynamic=dynamic,
                         dynamic_raw=dynamic_raw,
                         **kwargs)
        self.id_ = id_
        self.first_name = first_name
        self.last_name = last_name
        self.email = email
        self.gender = gender
        self.status = status
        self.position = position
        self.supervisor = supervisor
        self.employment_type = employment_type
        self.weekly_working_hours = weekly_working_hours
        self.hire_date = hire_date
        self.contract_end_date = contract_end_date
        self.termination_date = termination_date
        self.termination_type = termination_type
        self.termination_reason = termination_reason
        self.probation_period_end = probation_period_end
        self.created_at = created_at
        self.last_modified_at = last_modified_at
        self.subcompany = subcompany
        self.office = office
        self.department = department
        self.cost_centers = cost_centers
        self.holiday_calendar = holiday_calendar
        self.absence_entitlement = absence_entitlement
        self.work_schedule = work_schedule
        self.fix_salary = fix_salary
        self.fix_salary_interval = fix_salary_interval
        self.hourly_salary = hourly_salary
        self.vacation_day_balance = vacation_day_balance
        self.last_working_day = last_working_day
        self.profile_picture = profile_picture
        self.team = team
        self._picture = None

    def _create(self, client: 'Personio' = None):
        pass

    def _update(self, client: 'Personio' = None):
        pass

    def picture(self, client: 'Personio' = None, width: int = None) -> bytes:
        if self._picture is None:
            client = get_client(self, client)
            self._picture = client.get_employee_picture(self, width=width)
        return self._picture

    def __str__(self):
        return f"{self.__class__.__name__}: {self.first_name} {self.last_name}, " \
               f"{self.position or 'position undefined'} ({self.id_})"
Exemplo n.º 11
0
class Absence(WritablePersonioResource):

    _api_type_name = "TimeOffPeriod"
    _can_update = False
    _field_mapping_list = [
        NumericFieldMapping('id', 'id_', int),
        FieldMapping('status', 'status', str),
        FieldMapping('comment', 'comment', str),
        DateFieldMapping('start_date', 'start_date'),
        DateFieldMapping('end_date', 'end_date'),
        NumericFieldMapping('days_count', 'days_count', float),
        NumericFieldMapping('half_day_start', 'half_day_start', int),
        NumericFieldMapping('half_day_end', 'half_day_end', int),
        ObjectFieldMapping('time_off_type', 'time_off_type', AbsenceType),
        ObjectFieldMapping('employee', 'employee', ShortEmployee),
        FieldMapping('created_by', 'created_by', str),
        ObjectFieldMapping('certificate', 'certificate', Certificate),
        DateTimeFieldMapping('created_at', 'created_at'),
    ]

    def __init__(self,
                 client: 'Personio' = None,
                 dynamic: Dict[str, Any] = None,
                 dynamic_raw: List['DynamicAttr'] = None,
                 id_: int = None,
                 status: str = None,
                 comment: str = None,
                 start_date: datetime = None,
                 end_date: datetime = None,
                 days_count: float = None,
                 half_day_start: bool = False,
                 half_day_end: bool = False,
                 time_off_type: AbsenceType = None,
                 employee: ShortEmployee = None,
                 created_by: str = None,
                 certificate: Certificate = None,
                 created_at: datetime = None,
                 **kwargs):
        super().__init__(client=client,
                         dynamic=dynamic,
                         dynamic_raw=dynamic_raw,
                         **kwargs)
        self.id_ = id_
        self.status = status
        self.comment = comment
        self.start_date = start_date
        self.end_date = end_date
        self.days_count = days_count
        self.half_day_start = bool(half_day_start)
        self.half_day_end = bool(half_day_end)
        self.time_off_type = time_off_type
        self.employee = employee
        self.created_by = created_by
        self.certificate = certificate
        self.created_at = created_at

    def _create(self, client: 'Personio' = None):
        return get_client(self, client).create_absence(self)

    def _delete(self, client: 'Personio' = None):
        return get_client(self, client).delete_absence(self)

    def to_body_params(self):
        data = {
            'employee_id': self.employee.id_,
            'time_off_type_id': self.time_off_type.id_,
            'start_date': self.start_date.strftime("%Y-%m-%d"),
            'end_date': self.end_date.strftime("%Y-%m-%d"),
            'half_day_start': self.half_day_start,
            'half_day_end': self.half_day_end
        }
        if self.comment is not None:
            data['comment'] = self.comment
        return data