Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude existing beneficiaries from the target location report form #529

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/project_reports/views/report_target_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,26 @@ def get_target_and_reached_of_disaggregationlocation(request):
if not target_location_id or not disaggregation_id:
return JsonResponse({"error": "Both target_location_id and disaggregation_id are required."}, status=400)

try:
target_location_id = int(target_location_id)
disaggregation_id = int(disaggregation_id)
except ValueError:
return JsonResponse({"error": "Both target_location_id and disaggregation_id must be integers."}, status=400)

dis_loc = DisaggregationLocation.objects.filter(
disaggregation_id=disaggregation_id, target_location_id=target_location_id
).first()

total_reached = DisaggregationLocationReport.objects.filter(
target_location_report__target_location_id=target_location_id, disaggregation_id=disaggregation_id
).aggregate(total_reached=Sum("reached"))["total_reached"]
total_reached = (
DisaggregationLocationReport.objects.filter(
target_location_report__target_location_id=target_location_id,
disaggregation_id=disaggregation_id,
)
.filter(
target_location_report__beneficiary_status="new_beneficiary",
)
.aggregate(total_reached=Sum("reached"))["total_reached"]
)

return JsonResponse({"target": dis_loc.target, "reached": total_reached})

Expand Down
Loading