From 5ceb2a363cc0c8b8dde127c59d8d8ce760c03332 Mon Sep 17 00:00:00 2001 From: Shahryar Tayeb Date: Tue, 17 Dec 2024 12:14:29 +0430 Subject: [PATCH] exclude new_beneficiary from 5w --- src/project_reports/views/dashboards.py | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/project_reports/views/dashboards.py b/src/project_reports/views/dashboards.py index 18d85f71..3e2c1845 100644 --- a/src/project_reports/views/dashboards.py +++ b/src/project_reports/views/dashboards.py @@ -3,7 +3,7 @@ from django.contrib.auth.decorators import login_required from django.core.cache import cache from django.core.exceptions import PermissionDenied -from django.db.models import Count, Sum, Value +from django.db.models import Case, Count, IntegerField, Sum, Value, When from django.db.models.functions import Coalesce from django.shortcuts import get_object_or_404, render @@ -68,7 +68,17 @@ def cluster_5w_dashboard(request, cluster): .values("from_date") .annotate( total_people_reached=Coalesce( - Sum("activityplanreport__targetlocationreport__disaggregationlocationreport__reached"), Value(0) + Sum( + Case( + When( + activityplanreport__targetlocationreport__beneficiary_status="new_beneficiary", + then="activityplanreport__targetlocationreport__disaggregationlocationreport__reached", + ), + default=Value(0), + output_field=IntegerField(), + ) + ), + Value(0), ) ) ) @@ -183,7 +193,17 @@ def org_5w_dashboard(request, code): .values("from_date") .annotate( total_people_reached=Coalesce( - Sum("activityplanreport__targetlocationreport__disaggregationlocationreport__reached"), Value(0) + Sum( + Case( + When( + activityplanreport__targetlocationreport__beneficiary_status="new_beneficiary", + then="activityplanreport__targetlocationreport__disaggregationlocationreport__reached", + ), + default=Value(0), + output_field=IntegerField(), + ) + ), + Value(0), ) ) )