Skip to content

timesheets

main.management.commands.timesheets ¤

Timesheets management command.

Classes¤

Command ¤

Bases: BaseCommand

Management command to retrieve timesheets.

Methods:¤
add_arguments(parser) ¤

Arguments to be parsed from the input.

Source code in main/management/commands/timesheets.py
18
19
20
21
22
23
24
25
def add_arguments(self, parser):  # type: ignore[no-untyped-def]
    """Arguments to be parsed from the input."""
    parser.add_argument(
        "-t", "--time", type=int, help="Time entries logged in last TIME days"
    )
    parser.add_argument(
        "-p", "--project", type=int, help="PROJECT id to get time entries for."
    )
handle(*args, **kwargs) ¤

Actual function to be executed.

Source code in main/management/commands/timesheets.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def handle(self, *args, **kwargs):  # type: ignore[no-untyped-def]
    """Actual function to be executed."""
    days = kwargs.get("time")
    if not days:
        raise ValueError("A integer number of days must be provided.")
    project_id = kwargs.get("project")
    if not project_id:
        raise ValueError("A project ID number must be provided.")

    end_date = timezone.now()
    start_date = end_date - timedelta(days=days)

    kimai = KimaiAPI(settings.KIMAI_API_TOKEN, settings.KIMAI_BASE_URL)
    entries = kimai.get_time_entries(start_date, end_date, project_id)

    pprint(entries)