Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
feat: empty sums in correcr ordering
Browse files Browse the repository at this point in the history
The statistics should report zero hours instead of NULL. This makes
the ordering of data actually work as expected
  • Loading branch information
winged committed Feb 28, 2023
1 parent 757ac53 commit 757de4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions timed/reports/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db.models import F, Q, Sum
from django.db.models import DurationField, F, Q, Sum, Value
from django.db.models.functions import Coalesce
from django_filters.rest_framework import (
BaseInFilter,
DateFilter,
Expand Down Expand Up @@ -82,7 +83,11 @@ def filter_queryset(self, queryset):
duration_ref = self._refs["reports_ref"] + "__duration"

full_qs = qs._base.annotate(
duration=Sum(duration_ref, filter=qs._agg_filters), pk=F("id")
duration=Coalesce(
Sum(duration_ref, filter=qs._agg_filters),
Value("00:00:00", DurationField(null=False)),
),
pk=F("id"),
)
result = full_qs.values()
# Useful for QS debugging
Expand Down
6 changes: 3 additions & 3 deletions timed/reports/tests/test_customer_statistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ def test_customer_statistic_list(
},
]
if third_customer:
expected_data.append(
expected_data = [
{
"type": "customer-statistics",
"id": str(third_customer.pk),
"attributes": {
"duration": None,
"duration": "00:00:00",
"name": third_customer.name,
},
}
)
] + expected_data
assert json["data"] == expected_data
assert json["meta"]["total-time"] == "07:00:00"

Expand Down

0 comments on commit 757de4e

Please sign in to comment.