projectal.entities.staff

  1from datetime import datetime
  2
  3import projectal
  4from projectal.entity import Entity
  5from projectal.linkers import *
  6
  7
  8class Staff(
  9    Entity,
 10    LocationLinker,
 11    ResourceLinker,
 12    SkillLinker,
 13    FileLinker,
 14    CompanyLinker,
 15    DepartmentLinker,
 16    TaskLinker,
 17    TaskTemplateLinker,
 18    NoteLinker,
 19    CalendarLinker,
 20    TagLinker,
 21):
 22    """
 23    Implementation of the [Staff](https://projectal.com/docs/latest/#tag/Staff) API.
 24    """
 25
 26    _path = "staff"
 27    _name = "staff"
 28    _links = [
 29        LocationLinker,
 30        ResourceLinker,
 31        SkillLinker,
 32        FileLinker,
 33        NoteLinker,
 34        CalendarLinker,
 35        TagLinker,
 36    ]
 37    _links_reverse = [CompanyLinker, DepartmentLinker, TaskLinker, TaskTemplateLinker]
 38
 39    @classmethod
 40    def calendar(cls, uuId, begin=None, until=None):
 41        """
 42        Returns the calendar of the staff with `uuId`.
 43
 44        `begin`: Start date in `yyyy-MM-dd`.
 45
 46        `until`: End date in `yyyy-MM-dd`.
 47
 48
 49        Optionally specify a date range. If no range specified, the
 50        minimum and maximum dates are used (see projectal.enums.DateLimit).
 51        """
 52        if begin:
 53            begin = datetime.strptime(begin, "%Y-%m-%d").date()
 54        if until:
 55            until = datetime.strptime(until, "%Y-%m-%d").date()
 56
 57        url = "/api/staff/{}/calendar?".format(uuId)
 58        params = []
 59        params.append("begin={}".format(begin)) if begin else None
 60        params.append("until={}".format(until)) if until else None
 61        url += "&".join(params)
 62
 63        cals = api.get(url)
 64        cals = [projectal.Calendar(c) for c in cals]
 65        return cals
 66
 67    @classmethod
 68    def calendar_availability(cls, uuId, begin=None, until=None):
 69        """
 70        Returns the availability (in hours) of the staff in `uuId`
 71        for each day within the specified date range.
 72
 73        `begin`: Start date in `yyyy-MM-dd`.
 74
 75        `until`: End date in `yyyy-MM-dd`.
 76
 77        If no range specified, the minimum and maximum dates are
 78        used (see projectal.enums.DateLimit).
 79        """
 80        if begin:
 81            begin = datetime.strptime(begin, "%Y-%m-%d").date()
 82        if until:
 83            until = datetime.strptime(until, "%Y-%m-%d").date()
 84
 85        url = "/api/staff/{}/calendar/availability?".format(uuId)
 86        params = []
 87        params.append("begin={}".format(begin)) if begin else None
 88        params.append("until={}".format(until)) if until else None
 89        url += "&".join(params)
 90
 91        return api.get(url)
 92
 93    @classmethod
 94    def usage(
 95        cls,
 96        begin,
 97        until,
 98        holder=None,
 99        start=None,
100        limit=None,
101        span=None,
102        ksort=None,
103        order=None,
104        staff=None,
105    ):
106        """
107        Returns the staff-to-task allocations for all staff within the `holder`.
108
109        See [Usage API](https://projectal.com/docs/latest/#tag/Staff/paths/~1api~1staff~1usage/post)
110        for full details.
111        """
112        url = "/api/staff/usage?begin={}&until={}".format(begin, until)
113        params = []
114        params.append("holder={}".format(holder)) if holder else None
115        params.append("start={}".format(start)) if start else None
116        params.append("limit={}".format(limit)) if limit else None
117        params.append("span={}".format(span)) if span else None
118        params.append("ksort={}".format(ksort)) if ksort else None
119        params.append("order={}".format(order)) if order else None
120        if len(params) > 0:
121            url += "&" + "&".join(params)
122        payload = staff if staff and not holder else None
123        response = api.post(url, payload)
124        # Do some extra checks for empty list case
125        if "status" in response:
126            # We didn't have a 'jobCase' key and returned the outer dict.
127            return []
128        return response
129
130    @classmethod
131    def auto_assign(
132        cls,
133        type="Recommend",
134        over_allocate_staff=False,
135        include_assigned_task=False,
136        include_started_task=False,
137        skills=None,
138        tasks=None,
139        staffs=None,
140    ):
141        """
142        Automatically assign a set of staff (real or generic) to a set of tasks
143        using various skill and allocation criteria.
144
145        See [Staff Assign API](https://projectal.com/docs/latest/#tag/Staff-Assign/paths/~1api~1allocation~1staff/post)
146        for full details.
147        """
148        url = "/api/allocation/staff"
149        payload = {
150            "type": type,
151            "overAllocateStaff": over_allocate_staff,
152            "includeAssignedTask": include_assigned_task,
153            "includeStartedTask": include_started_task,
154            "skillMatchList": skills if skills else [],
155            "staffList": staffs if staffs else [],
156            "taskList": tasks if tasks else [],
157        }
158        return api.post(url, payload)
  9class Staff(
 10    Entity,
 11    LocationLinker,
 12    ResourceLinker,
 13    SkillLinker,
 14    FileLinker,
 15    CompanyLinker,
 16    DepartmentLinker,
 17    TaskLinker,
 18    TaskTemplateLinker,
 19    NoteLinker,
 20    CalendarLinker,
 21    TagLinker,
 22):
 23    """
 24    Implementation of the [Staff](https://projectal.com/docs/latest/#tag/Staff) API.
 25    """
 26
 27    _path = "staff"
 28    _name = "staff"
 29    _links = [
 30        LocationLinker,
 31        ResourceLinker,
 32        SkillLinker,
 33        FileLinker,
 34        NoteLinker,
 35        CalendarLinker,
 36        TagLinker,
 37    ]
 38    _links_reverse = [CompanyLinker, DepartmentLinker, TaskLinker, TaskTemplateLinker]
 39
 40    @classmethod
 41    def calendar(cls, uuId, begin=None, until=None):
 42        """
 43        Returns the calendar of the staff with `uuId`.
 44
 45        `begin`: Start date in `yyyy-MM-dd`.
 46
 47        `until`: End date in `yyyy-MM-dd`.
 48
 49
 50        Optionally specify a date range. If no range specified, the
 51        minimum and maximum dates are used (see projectal.enums.DateLimit).
 52        """
 53        if begin:
 54            begin = datetime.strptime(begin, "%Y-%m-%d").date()
 55        if until:
 56            until = datetime.strptime(until, "%Y-%m-%d").date()
 57
 58        url = "/api/staff/{}/calendar?".format(uuId)
 59        params = []
 60        params.append("begin={}".format(begin)) if begin else None
 61        params.append("until={}".format(until)) if until else None
 62        url += "&".join(params)
 63
 64        cals = api.get(url)
 65        cals = [projectal.Calendar(c) for c in cals]
 66        return cals
 67
 68    @classmethod
 69    def calendar_availability(cls, uuId, begin=None, until=None):
 70        """
 71        Returns the availability (in hours) of the staff in `uuId`
 72        for each day within the specified date range.
 73
 74        `begin`: Start date in `yyyy-MM-dd`.
 75
 76        `until`: End date in `yyyy-MM-dd`.
 77
 78        If no range specified, the minimum and maximum dates are
 79        used (see projectal.enums.DateLimit).
 80        """
 81        if begin:
 82            begin = datetime.strptime(begin, "%Y-%m-%d").date()
 83        if until:
 84            until = datetime.strptime(until, "%Y-%m-%d").date()
 85
 86        url = "/api/staff/{}/calendar/availability?".format(uuId)
 87        params = []
 88        params.append("begin={}".format(begin)) if begin else None
 89        params.append("until={}".format(until)) if until else None
 90        url += "&".join(params)
 91
 92        return api.get(url)
 93
 94    @classmethod
 95    def usage(
 96        cls,
 97        begin,
 98        until,
 99        holder=None,
100        start=None,
101        limit=None,
102        span=None,
103        ksort=None,
104        order=None,
105        staff=None,
106    ):
107        """
108        Returns the staff-to-task allocations for all staff within the `holder`.
109
110        See [Usage API](https://projectal.com/docs/latest/#tag/Staff/paths/~1api~1staff~1usage/post)
111        for full details.
112        """
113        url = "/api/staff/usage?begin={}&until={}".format(begin, until)
114        params = []
115        params.append("holder={}".format(holder)) if holder else None
116        params.append("start={}".format(start)) if start else None
117        params.append("limit={}".format(limit)) if limit else None
118        params.append("span={}".format(span)) if span else None
119        params.append("ksort={}".format(ksort)) if ksort else None
120        params.append("order={}".format(order)) if order else None
121        if len(params) > 0:
122            url += "&" + "&".join(params)
123        payload = staff if staff and not holder else None
124        response = api.post(url, payload)
125        # Do some extra checks for empty list case
126        if "status" in response:
127            # We didn't have a 'jobCase' key and returned the outer dict.
128            return []
129        return response
130
131    @classmethod
132    def auto_assign(
133        cls,
134        type="Recommend",
135        over_allocate_staff=False,
136        include_assigned_task=False,
137        include_started_task=False,
138        skills=None,
139        tasks=None,
140        staffs=None,
141    ):
142        """
143        Automatically assign a set of staff (real or generic) to a set of tasks
144        using various skill and allocation criteria.
145
146        See [Staff Assign API](https://projectal.com/docs/latest/#tag/Staff-Assign/paths/~1api~1allocation~1staff/post)
147        for full details.
148        """
149        url = "/api/allocation/staff"
150        payload = {
151            "type": type,
152            "overAllocateStaff": over_allocate_staff,
153            "includeAssignedTask": include_assigned_task,
154            "includeStartedTask": include_started_task,
155            "skillMatchList": skills if skills else [],
156            "staffList": staffs if staffs else [],
157            "taskList": tasks if tasks else [],
158        }
159        return api.post(url, payload)

Implementation of the Staff API.

@classmethod
def calendar(cls, uuId, begin=None, until=None):
40    @classmethod
41    def calendar(cls, uuId, begin=None, until=None):
42        """
43        Returns the calendar of the staff with `uuId`.
44
45        `begin`: Start date in `yyyy-MM-dd`.
46
47        `until`: End date in `yyyy-MM-dd`.
48
49
50        Optionally specify a date range. If no range specified, the
51        minimum and maximum dates are used (see projectal.enums.DateLimit).
52        """
53        if begin:
54            begin = datetime.strptime(begin, "%Y-%m-%d").date()
55        if until:
56            until = datetime.strptime(until, "%Y-%m-%d").date()
57
58        url = "/api/staff/{}/calendar?".format(uuId)
59        params = []
60        params.append("begin={}".format(begin)) if begin else None
61        params.append("until={}".format(until)) if until else None
62        url += "&".join(params)
63
64        cals = api.get(url)
65        cals = [projectal.Calendar(c) for c in cals]
66        return cals

Returns the calendar of the staff with uuId.

begin: Start date in yyyy-MM-dd.

until: End date in yyyy-MM-dd.

Optionally specify a date range. If no range specified, the minimum and maximum dates are used (see projectal.enums.DateLimit).

@classmethod
def calendar_availability(cls, uuId, begin=None, until=None):
68    @classmethod
69    def calendar_availability(cls, uuId, begin=None, until=None):
70        """
71        Returns the availability (in hours) of the staff in `uuId`
72        for each day within the specified date range.
73
74        `begin`: Start date in `yyyy-MM-dd`.
75
76        `until`: End date in `yyyy-MM-dd`.
77
78        If no range specified, the minimum and maximum dates are
79        used (see projectal.enums.DateLimit).
80        """
81        if begin:
82            begin = datetime.strptime(begin, "%Y-%m-%d").date()
83        if until:
84            until = datetime.strptime(until, "%Y-%m-%d").date()
85
86        url = "/api/staff/{}/calendar/availability?".format(uuId)
87        params = []
88        params.append("begin={}".format(begin)) if begin else None
89        params.append("until={}".format(until)) if until else None
90        url += "&".join(params)
91
92        return api.get(url)

Returns the availability (in hours) of the staff in uuId for each day within the specified date range.

begin: Start date in yyyy-MM-dd.

until: End date in yyyy-MM-dd.

If no range specified, the minimum and maximum dates are used (see projectal.enums.DateLimit).

@classmethod
def usage( cls, begin, until, holder=None, start=None, limit=None, span=None, ksort=None, order=None, staff=None):
 94    @classmethod
 95    def usage(
 96        cls,
 97        begin,
 98        until,
 99        holder=None,
100        start=None,
101        limit=None,
102        span=None,
103        ksort=None,
104        order=None,
105        staff=None,
106    ):
107        """
108        Returns the staff-to-task allocations for all staff within the `holder`.
109
110        See [Usage API](https://projectal.com/docs/latest/#tag/Staff/paths/~1api~1staff~1usage/post)
111        for full details.
112        """
113        url = "/api/staff/usage?begin={}&until={}".format(begin, until)
114        params = []
115        params.append("holder={}".format(holder)) if holder else None
116        params.append("start={}".format(start)) if start else None
117        params.append("limit={}".format(limit)) if limit else None
118        params.append("span={}".format(span)) if span else None
119        params.append("ksort={}".format(ksort)) if ksort else None
120        params.append("order={}".format(order)) if order else None
121        if len(params) > 0:
122            url += "&" + "&".join(params)
123        payload = staff if staff and not holder else None
124        response = api.post(url, payload)
125        # Do some extra checks for empty list case
126        if "status" in response:
127            # We didn't have a 'jobCase' key and returned the outer dict.
128            return []
129        return response

Returns the staff-to-task allocations for all staff within the holder.

See Usage API for full details.

@classmethod
def auto_assign( cls, type='Recommend', over_allocate_staff=False, include_assigned_task=False, include_started_task=False, skills=None, tasks=None, staffs=None):
131    @classmethod
132    def auto_assign(
133        cls,
134        type="Recommend",
135        over_allocate_staff=False,
136        include_assigned_task=False,
137        include_started_task=False,
138        skills=None,
139        tasks=None,
140        staffs=None,
141    ):
142        """
143        Automatically assign a set of staff (real or generic) to a set of tasks
144        using various skill and allocation criteria.
145
146        See [Staff Assign API](https://projectal.com/docs/latest/#tag/Staff-Assign/paths/~1api~1allocation~1staff/post)
147        for full details.
148        """
149        url = "/api/allocation/staff"
150        payload = {
151            "type": type,
152            "overAllocateStaff": over_allocate_staff,
153            "includeAssignedTask": include_assigned_task,
154            "includeStartedTask": include_started_task,
155            "skillMatchList": skills if skills else [],
156            "staffList": staffs if staffs else [],
157            "taskList": tasks if tasks else [],
158        }
159        return api.post(url, payload)

Automatically assign a set of staff (real or generic) to a set of tasks using various skill and allocation criteria.

See Staff Assign API for full details.