feat(reports): load user summaries on demand
This commit is contained in:
@@ -10,7 +10,7 @@ from apps.projects.models import Project
|
||||
from apps.tags.models import Tag
|
||||
from apps.time_entries.models import TimeEntry
|
||||
from apps.users.models import User
|
||||
from apps.workspaces.models import Workspace, WorkspaceMembership
|
||||
from apps.workspaces.models import Workspace, WorkspaceMembership, WorkspaceUserRate
|
||||
|
||||
|
||||
class ReportViewTests(APITestCase):
|
||||
@@ -320,6 +320,75 @@ class ReportViewTests(APITestCase):
|
||||
{"amount": "35.00", "currency": "USD"},
|
||||
)
|
||||
|
||||
def test_user_summary_endpoint_keeps_workspace_rate_history_and_marks_current_row_open(self):
|
||||
self.client.force_authenticate(user=self.owner)
|
||||
|
||||
TimeEntry.objects.create(
|
||||
workspace=self.workspace,
|
||||
user=self.owner,
|
||||
project=None,
|
||||
description="Legacy workspace rate",
|
||||
start_time="2026-04-08T08:00:00+03:30",
|
||||
end_time="2026-04-08T09:00:00+03:30",
|
||||
duration=timedelta(hours=1),
|
||||
is_billable=True,
|
||||
hourly_rate=Decimal("12.00"),
|
||||
currency="USD",
|
||||
)
|
||||
TimeEntry.objects.create(
|
||||
workspace=self.workspace,
|
||||
user=self.owner,
|
||||
project=self.project,
|
||||
description="Current project rate",
|
||||
start_time="2026-04-12T08:00:00+03:30",
|
||||
end_time="2026-04-12T10:00:00+03:30",
|
||||
duration=timedelta(hours=2),
|
||||
is_billable=True,
|
||||
hourly_rate=Decimal("25.00"),
|
||||
currency="USD",
|
||||
)
|
||||
WorkspaceUserRate.objects.create(
|
||||
workspace=self.workspace,
|
||||
user=self.owner,
|
||||
hourly_rate=Decimal("12.00"),
|
||||
currency="USD",
|
||||
effective_from="2026-04-01T00:00:00+03:30",
|
||||
is_active=True,
|
||||
)
|
||||
|
||||
with patch(
|
||||
"apps.reports.services.aggregation.timezone.localdate",
|
||||
return_value=date(2026, 4, 20),
|
||||
):
|
||||
response = self.client.get(
|
||||
"/api/reports/user-summary/",
|
||||
{
|
||||
"workspace": str(self.workspace.id),
|
||||
"period": "this_month",
|
||||
"user": str(self.owner.id),
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
rate_periods = response.data["user_summary"]["rate_periods"]
|
||||
self.assertEqual(
|
||||
rate_periods,
|
||||
[
|
||||
{
|
||||
"amount": "12.00",
|
||||
"currency": "USD",
|
||||
"from_date": "2026-04-08",
|
||||
"to_date": None,
|
||||
},
|
||||
{
|
||||
"amount": "25.00",
|
||||
"currency": "USD",
|
||||
"from_date": "2026-04-10",
|
||||
"to_date": "2026-04-12",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
def test_custom_period_longer_than_31_days_is_rejected(self):
|
||||
self.client.force_authenticate(user=self.owner)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user