diff --git a/backend/common/views/dashboard_views.py b/backend/common/views/dashboard_views.py index 36fe6be4..2a710f32 100644 --- a/backend/common/views/dashboard_views.py +++ b/backend/common/views/dashboard_views.py @@ -223,7 +223,7 @@ class ApiHomeView(APIView): from opportunity.models import SalesGoal goal_filter = Q(assigned_to=profile) | Q(team__in=profile.user_teams.all()) - if profile.role == "ADMIN": + if is_admin: goal_filter |= Q(assigned_to__isnull=True, team__isnull=True) active_goals = ( diff --git a/backend/opportunity/tests/test_sales_goals.py b/backend/opportunity/tests/test_sales_goals.py index 4817afce..f6612161 100644 --- a/backend/opportunity/tests/test_sales_goals.py +++ b/backend/opportunity/tests/test_sales_goals.py @@ -257,7 +257,7 @@ class TestSalesGoalAPI: ), } response = admin_client.post(self.GOALS_URL, data, format="json") - assert response.status_code == 200 + assert response.status_code == 201 assert response.data["error"] is False assert SalesGoal.objects.filter(name="New Goal", org=org_a).exists() diff --git a/backend/opportunity/views/goal_views.py b/backend/opportunity/views/goal_views.py index f3047265..518dc908 100644 --- a/backend/opportunity/views/goal_views.py +++ b/backend/opportunity/views/goal_views.py @@ -44,7 +44,9 @@ class SalesGoalListView(APIView, LimitOffsetPagination): if params.get("search"): queryset = queryset.filter(name__icontains=params["search"]) - return queryset.distinct() + return queryset.select_related( + "assigned_to", "assigned_to__user", "team" + ).distinct() def get(self, request, *args, **kwargs): queryset = self.get_queryset(request) @@ -52,11 +54,8 @@ class SalesGoalListView(APIView, LimitOffsetPagination): serializer = SalesGoalSerializer(results, many=True) total_count = self.count - offset = None - if results: - offset = queryset.filter(id__gte=results[-1].id).count() - if offset == total_count: - offset = None + next_offset = self.offset + len(results) if results else None + offset = next_offset if (results and next_offset < total_count) else None return Response( { @@ -82,7 +81,7 @@ class SalesGoalListView(APIView, LimitOffsetPagination): ) return Response( {"error": False, "message": "Goal Created Successfully"}, - status=status.HTTP_200_OK, + status=status.HTTP_201_CREATED, ) return Response( {"error": True, "errors": serializer.errors}, diff --git a/frontend/src/lib/components/dashboard/GoalProgress.svelte b/frontend/src/lib/components/dashboard/GoalProgress.svelte index f9c2f5e8..eddd026c 100644 --- a/frontend/src/lib/components/dashboard/GoalProgress.svelte +++ b/frontend/src/lib/components/dashboard/GoalProgress.svelte @@ -4,39 +4,12 @@ import { formatCurrency } from '$lib/utils/formatting.js'; import { orgSettings } from '$lib/stores/org.js'; import { resolve } from '$app/paths'; + import { getStatusColor, getProgressColor } from '$lib/utils/goals.js'; /** @type {{ goals?: any[] }} */ let { goals = [] } = $props(); const orgCurrency = $derived($orgSettings.default_currency || 'USD'); - - /** - * @param {string} statusValue - */ - function getStatusColor(statusValue) { - switch (statusValue) { - case 'on_track': - return 'text-emerald-600 dark:text-emerald-400'; - case 'at_risk': - return 'text-amber-600 dark:text-amber-400'; - case 'behind': - return 'text-red-600 dark:text-red-400'; - case 'completed': - return 'text-blue-600 dark:text-blue-400'; - default: - return 'text-[var(--text-secondary)]'; - } - } - - /** - * @param {number} percent - */ - function getProgressColor(percent) { - if (percent >= 100) return '[&>[data-slot=progress-indicator]]:bg-blue-500'; - if (percent >= 75) return '[&>[data-slot=progress-indicator]]:bg-emerald-500'; - if (percent >= 50) return '[&>[data-slot=progress-indicator]]:bg-amber-500'; - return '[&>[data-slot=progress-indicator]]:bg-red-500'; - }