Skip to content

Commit

Permalink
Merge pull request #507 from iMMAP/chore/exclude_new_benef_from_5w
Browse files Browse the repository at this point in the history
exclude new_beneficiary from 5w
  • Loading branch information
shtayeb authored Dec 17, 2024
2 parents 9f89061 + 5ceb2a3 commit 5f33ddb
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/project_reports/views/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
)
)
)
Expand Down Expand Up @@ -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),
)
)
)
Expand Down

0 comments on commit 5f33ddb

Please sign in to comment.