From ec245fe029259edb38f084ad43ea7b8ee9b8f58c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Hermida?= Date: Thu, 13 Sep 2018 12:10:15 +0200 Subject: [PATCH] Fix closed us count in profile #1121 --- taiga/users/services.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/taiga/users/services.py b/taiga/users/services.py index 8920ee74..d49c07b2 100644 --- a/taiga/users/services.py +++ b/taiga/users/services.py @@ -29,7 +29,7 @@ import zipfile from django.apps import apps from django.contrib.auth import get_user_model from django.core.files.storage import default_storage -from django.db.models import Q +from django.db.models import OuterRef, Q, Subquery from django.db import connection from django.conf import settings from django.contrib.contenttypes.models import ContentType @@ -155,10 +155,14 @@ def get_stats_for_user(from_user, by_user): .count() UserStory = apps.get_model('userstories', 'UserStory') + + assigned_users_ids = UserStory.objects.order_by().filter( + assigned_users__in=[from_user], id=OuterRef('pk')).values('pk') + total_num_closed_userstories = UserStory.objects.filter( is_closed=True, - project__id__in=project_ids, - assigned_to=from_user).count() + project__id__in=project_ids).filter( + Q(assigned_to=from_user) | Q(pk__in=Subquery(assigned_users_ids))).count() project_stats = { 'total_num_projects': total_num_projects,