Skip to content

Commit

Permalink
fix(backend): provide total billable time in task meta
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Jan 31, 2025
1 parent 76b2bb7 commit 77b986a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/timed/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def get_root_meta(self, _resource, many):
queryset = Report.objects.filter(task=self.instance)
data = queryset.aggregate(spent_time=Sum("duration"))
data["spent_time"] = duration_string(data["spent_time"] or timedelta(0))
billable_data = queryset.filter(not_billable=False, review=False).aggregate(
spent_billable=Sum("duration")
)
data["spent_billable"] = duration_string(
billable_data["spent_billable"] or timedelta(0)
)

return data

return {}
Expand Down
16 changes: 16 additions & 0 deletions backend/timed/projects/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def test_task_detail_no_reports(internal_employee_client, task):

json = res.json()
assert json["meta"]["spent-time"] == "00:00:00"
assert json["meta"]["spent-billable"] == "00:00:00"


def test_task_detail_with_reports(internal_employee_client, task, report_factory):
Expand All @@ -204,6 +205,7 @@ def test_task_detail_with_reports(internal_employee_client, task, report_factory

json = res.json()
assert json["meta"]["spent-time"] == "02:30:00"
assert json["meta"]["spent-billable"] == "02:30:00"


@pytest.mark.parametrize(("is_assigned", "expected"), [(True, 1), (False, 0)])
Expand Down Expand Up @@ -263,3 +265,17 @@ def test_task_multi_number_value_filter(internal_employee_client):

json = response.json()
assert len(json["data"]) == 2


def test_task_detail_spent_billable(internal_employee_client, task, report_factory):
report_factory.create(task=task, duration=timedelta(minutes=30), not_billable=True)

url = reverse("task-detail", args=[task.id])

res = internal_employee_client.get(url)

assert res.status_code == status.HTTP_200_OK

json = res.json()
assert json["meta"]["spent-time"] == "00:30:00"
assert json["meta"]["spent-billable"] == "00:00:00"

0 comments on commit 77b986a

Please sign in to comment.