From c6ba93da728d162aff59f586f8270f76885446a7 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Sat, 25 Mar 2023 11:13:14 +0530 Subject: [PATCH] fix: dashboard issues filters (#519) * fix: upcoming issues filters * dev: update dashboard endpoint to return correct month --- apiserver/plane/api/views/workspace.py | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/apiserver/plane/api/views/workspace.py b/apiserver/plane/api/views/workspace.py index 46cff9fb6..a1778c5f3 100644 --- a/apiserver/plane/api/views/workspace.py +++ b/apiserver/plane/api/views/workspace.py @@ -11,8 +11,15 @@ from django.utils import timezone from django.core.exceptions import ValidationError from django.core.validators import validate_email from django.contrib.sites.shortcuts import get_current_site -from django.db.models import CharField, Count, OuterRef, Func, F, Q -from django.db.models.functions import Cast, ExtractWeek +from django.db.models import ( + CharField, + Count, + OuterRef, + Func, + F, + Q, +) +from django.db.models.functions import ExtractWeek, Cast, ExtractDay from django.db.models.fields import DateField # Third party modules @@ -636,6 +643,11 @@ class UserIssueCompletedGraphEndpoint(BaseAPIView): ) +class WeekInMonth(Func): + function = "FLOOR" + template = "(((%(expressions)s - 1) / 7) + 1)::INTEGER" + + class UserWorkspaceDashboardEndpoint(BaseAPIView): def get(self, request, slug): try: @@ -652,6 +664,7 @@ class UserWorkspaceDashboardEndpoint(BaseAPIView): ) month = request.GET.get("month", 1) + completed_issues = ( Issue.objects.filter( assignees__in=[request.user], @@ -659,11 +672,11 @@ class UserWorkspaceDashboardEndpoint(BaseAPIView): completed_at__month=month, completed_at__isnull=False, ) - .annotate(completed_week=ExtractWeek("completed_at")) - .annotate(week=F("completed_week") % 4) - .values("week") - .annotate(completed_count=Count("completed_week")) - .order_by("week") + .annotate(day_of_month=ExtractDay("completed_at")) + .annotate(week_in_month=WeekInMonth(F("day_of_month"))) + .values("week_in_month") + .annotate(completed_count=Count("id")) + .order_by("week_in_month") ) assigned_issues = Issue.objects.filter( @@ -710,7 +723,7 @@ class UserWorkspaceDashboardEndpoint(BaseAPIView): upcoming_issues = Issue.objects.filter( ~Q(state__group__in=["completed", "cancelled"]), - ~Q(target_date__gte=timezone.now()), + target_date__gte=timezone.now(), workspace__slug=slug, assignees__in=[request.user], completed_at__isnull=True,