Skip to content

ClockifyStart

ClockifyStart

Bases: LauncherAction

Source code in client/ayon_clockify/launcher_actions/ClockifyStart.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class ClockifyStart(LauncherAction):
    name = "clockify_start_timer"
    label = "Clockify - Start Timer"
    icon = "app_icons/clockify.png"
    order = 500
    clockify_api = ClockifyAPI()

    def is_compatible(self, selection):
        """Return whether the action is compatible with the session"""
        return selection.is_task_selected

    def process(self, selection, **kwargs):
        self.clockify_api.set_api()
        user_id = self.clockify_api.user_id
        workspace_id = self.clockify_api.workspace_id
        project_name = selection.project_name
        folder_path = selection.folder_path
        task_name = selection.task_name
        description = "/".join([folder_path.lstrip("/"), task_name])

        # fetch folder entity
        folder_entity = ayon_api.get_folder_by_path(project_name, folder_path)
        task_entity = ayon_api.get_task_by_name(
            project_name, folder_entity["id"], task_name
        )

        # get task type to fill the timer tag
        task_type = task_entity["taskType"]

        project_id = self.clockify_api.get_project_id(
            project_name, workspace_id
        )
        tag_ids = []
        tag_name = task_type
        tag_ids.append(self.clockify_api.get_tag_id(tag_name, workspace_id))
        self.clockify_api.start_time_entry(
            description,
            project_id,
            tag_ids=tag_ids,
            workspace_id=workspace_id,
            user_id=user_id,
        )

is_compatible(selection)

Return whether the action is compatible with the session

Source code in client/ayon_clockify/launcher_actions/ClockifyStart.py
15
16
17
def is_compatible(self, selection):
    """Return whether the action is compatible with the session"""
    return selection.is_task_selected