Skip to content

Ftr/dev 13014 add park to program activity #4456

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

Merged
merged 11 commits into from
Aug 11, 2025
Merged
14 changes: 14 additions & 0 deletions usaspending_api/agency/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ def agency_account_data():
oc, major_object_class=10, major_object_class_name="Other", object_class=140, object_class_name="interest"
)

pap1 = baker.make(
"references.ProgramActivityPark",
code="1",
name="PARK 1",
)

fabpaoc = "financial_activities.FinancialAccountsByProgramActivityObjectClass"
baker.make(
fabpaoc,
Expand All @@ -427,6 +433,7 @@ def agency_account_data():
ussgl498200_upward_adjust_pri_deliv_orders_oblig_paid_cpe=14,
ussgl480110_rein_undel_ord_cpe=75,
ussgl490110_rein_deliv_ord_cpe=63,
program_activity_reporting_key=pap1,
)
baker.make(
fabpaoc,
Expand Down Expand Up @@ -812,6 +819,12 @@ def tas_mulitple_pas_per_oc():

fabpaoc = "financial_activities.FinancialAccountsByProgramActivityObjectClass"

pap1 = baker.make(
"references.ProgramActivityPark",
code="1",
name="PARK 1",
)

baker.make(
fabpaoc,
treasury_account=tas1,
Expand All @@ -837,6 +850,7 @@ def tas_mulitple_pas_per_oc():
ussgl498200_upward_adjust_pri_deliv_orders_oblig_paid_cpe=0,
ussgl480110_rein_undel_ord_cpe=0,
ussgl490110_rein_deliv_ord_cpe=0,
program_activity_reporting_key=pap1,
)

baker.make(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_tas_program_activity_success(client, monkeypatch, agency_account_data,
"name": "NAME 3",
"gross_outlay_amount": 100000.0,
"obligated_amount": 100.0,
"type": "PAC/PAN",
"children": [
{
"name": "Other",
Expand All @@ -41,6 +42,7 @@ def test_tas_program_activity_success(client, monkeypatch, agency_account_data,
"name": "NAME 2",
"gross_outlay_amount": 1000000.0,
"obligated_amount": 10.0,
"type": "PAC/PAN",
"children": [
{
"name": "Other",
Expand All @@ -50,9 +52,10 @@ def test_tas_program_activity_success(client, monkeypatch, agency_account_data,
],
},
{
"name": "NAME 1",
"name": "PARK 1",
"gross_outlay_amount": 10000000.0,
"obligated_amount": 1.0,
"type": "PARK",
"children": [
{
"name": "Other",
Expand Down Expand Up @@ -111,6 +114,7 @@ def test_tas_program_activity_success(client, monkeypatch, agency_account_data,
"gross_outlay_amount": 1000000.0,
"name": "NAME 5",
"obligated_amount": 10.0,
"type": "PAC/PAN",
"children": [
{
"name": "Other",
Expand Down Expand Up @@ -151,6 +155,7 @@ def test_tas_multiple_program_activity_belonging_one_object_class(
"name": "NAME 2",
"gross_outlay_amount": 1000000.0,
"obligated_amount": 10.0,
"type": "PAC/PAN",
"children": [
{
"gross_outlay_amount": 1000000.0,
Expand All @@ -160,9 +165,10 @@ def test_tas_multiple_program_activity_belonging_one_object_class(
],
},
{
"name": "NAME 1",
"name": "PARK 1",
"gross_outlay_amount": 10000000.0,
"obligated_amount": 1.0,
"type": "PARK",
"children": [
{
"gross_outlay_amount": 10000000.0,
Expand Down Expand Up @@ -202,6 +208,7 @@ def test_tas_program_activity_multiple_submission_years(client, agency_account_d
"gross_outlay_amount": 10000.0,
"name": "NAME 4",
"obligated_amount": 1000.0,
"type": "PAC/PAN",
"children": [{"gross_outlay_amount": 10000.0, "name": "Other", "obligated_amount": 1000.0}],
}
],
Expand Down Expand Up @@ -235,6 +242,7 @@ def test_tas_program_activity_multiple_object_classes(client, tas_mulitple_oc_pe
"name": "NAME 4",
"gross_outlay_amount": 111000.0,
"obligated_amount": 11100.0,
"type": "PAC/PAN",
"children": [
{
"gross_outlay_amount": 101000.0,
Expand Down
23 changes: 18 additions & 5 deletions usaspending_api/agency/v2/views/tas_program_activity_list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, List

from django.db.models import Q, Sum, F
from django.db.models import Q, Sum, F, Case, When, Value, CharField
from django.db.models.functions import Coalesce
from rest_framework.request import Request
from rest_framework.response import Response

Expand Down Expand Up @@ -64,7 +65,10 @@ def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:

def get_program_activity_list(self) -> List[dict]:
filters = [
Q(program_activity__program_activity_name__isnull=False),
(
Q(program_activity_reporting_key__name__isnull=False)
| Q(program_activity__program_activity_name__isnull=False)
),
Q(submission_id__in=self.submission_ids),
Q(treasury_account__tas_rendering_label=self.tas_rendering_label),
self.file_b_calculations.is_non_zero_total_spending(),
Expand All @@ -75,21 +79,30 @@ def get_program_activity_list(self) -> List[dict]:
queryset_results = (
FinancialAccountsByProgramActivityObjectClass.objects.filter(*filters)
.values("program_activity__program_activity_name")
.values("program_activity_reporting_key__name")
.annotate(
name=F("program_activity__program_activity_name"),
name=Coalesce("program_activity_reporting_key__name", "program_activity__program_activity_name"),
obligated_amount=Sum(self.file_b_calculations.get_obligations()),
gross_outlay_amount=Sum(self.file_b_calculations.get_outlays()),
type=Case(
When(program_activity_reporting_key__name__isnull=False, then=Value("PARK")),
default=Value("PAC/PAN"),
output_field=CharField(),
),
)
.order_by(f"{'-' if self.pagination.sort_order == 'desc' else ''}{self.pagination.sort_key}")
.values("name", "obligated_amount", "gross_outlay_amount")
.values("name", "obligated_amount", "gross_outlay_amount", "type")
)
return queryset_results

def get_object_class_by_program_activity_list(self, program_activity_name) -> List[dict]:
filters = [
Q(object_class__major_object_class_name__isnull=False),
Q(submission_id__in=self.submission_ids),
Q(program_activity__program_activity_name=program_activity_name),
(
Q(program_activity__program_activity_name=program_activity_name)
| Q(program_activity_reporting_key__name=program_activity_name)
),
Q(treasury_account__tas_rendering_label=self.tas_rendering_label),
self.file_b_calculations.is_non_zero_total_spending(),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Returns a list of Program Activities for the specified Treasury Account Symbol (
+ `name`
+ `obligated_amount`
+ `gross_outlay_amount`
+ `type`
+ `page` (optional, number)
The page number that is currently returned.
+ Default: 1
Expand Down Expand Up @@ -93,6 +94,12 @@ Returns a list of Program Activities for the specified Treasury Account Symbol (
+ `name` (required, string)
+ `obligated_amount` (required, number)
+ `gross_outlay_amount` (required, number)
+ `type` (required, enum[string])
Indicates whether the values come from the Program Activity Reporting Key (PARK) or Program Activity Code/Name (PAC/PAN)
+ Default: `PARK`
+ Members
+ `PAC/PAN`
+ `PARK`
+ `children` (required, array[ObjectClass], fixed-type)

## ObjectClass (object)
Expand Down