Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): provide total billable time in task meta #587

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading