Skip to content

Commit 7d209cb

Browse files
authored
Merge pull request #2981 from fedspendingtransparency/staging
Sprint 126 Production Deploy
2 parents 65ba1db + 4ae29be commit 7d209cb

File tree

66 files changed

+2107
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2107
-681
lines changed

usaspending_api/accounts/tests/integration/test_federal_account.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from usaspending_api.accounts.models import FederalAccount, TreasuryAppropriationAccount
1414
from usaspending_api.financial_activities.models import FinancialAccountsByProgramActivityObjectClass
1515
from usaspending_api.references.models import RefProgramActivity
16+
from usaspending_api.submissions.models import SubmissionAttributes
1617

1718

1819
@pytest.mark.django_db
@@ -45,13 +46,15 @@ def test_federal_account_spending_by_category_unique_program_activity_names(clie
4546
"main_account_code": "8888",
4647
"budget_year": "2222",
4748
},
49+
{"model": SubmissionAttributes, "submission_id": 1, "is_final_balances_for_fy": True},
4850
{
4951
"model": FinancialAccountsByProgramActivityObjectClass,
5052
"financial_accounts_by_program_activity_object_class_id": -5,
5153
"obligations_incurred_by_program_object_class_cpe": -10,
5254
"final_of_fy": True,
5355
"treasury_account_id": -2,
5456
"program_activity_id": -3,
57+
"submission_id": 1,
5558
},
5659
{
5760
"model": FinancialAccountsByProgramActivityObjectClass,
@@ -60,6 +63,7 @@ def test_federal_account_spending_by_category_unique_program_activity_names(clie
6063
"final_of_fy": True,
6164
"treasury_account_id": -2,
6265
"program_activity_id": -4,
66+
"submission_id": 1,
6367
},
6468
]
6569

usaspending_api/accounts/tests/test_federal_account_fy_snapshot_v2.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77

88
@pytest.fixture
99
def financial_spending_data(db):
10-
latest_subm = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=2017)
11-
last_year_subm = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=2016)
10+
latest_subm = mommy.make(
11+
"submissions.SubmissionAttributes", reporting_fiscal_year=2017, is_final_balances_for_fy=True
12+
)
13+
not_latest_subm = mommy.make(
14+
"submissions.SubmissionAttributes", reporting_fiscal_year=2017, is_final_balances_for_fy=False
15+
)
16+
last_year_subm = mommy.make(
17+
"submissions.SubmissionAttributes", reporting_fiscal_year=2016, is_final_balances_for_fy=True
18+
)
1219
federal_account = mommy.make(FederalAccount, id=1)
1320

1421
# create Object classes
@@ -32,7 +39,7 @@ def financial_spending_data(db):
3239
"accounts.AppropriationAccountBalances",
3340
treasury_account_identifier__federal_account=federal_account,
3441
final_of_fy=False,
35-
submission=latest_subm,
42+
submission=not_latest_subm,
3643
gross_outlay_amount_by_tas_cpe=999,
3744
)
3845
mommy.make(

usaspending_api/accounts/tests/test_federal_obligations.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
@pytest.fixture
88
def financial_obligations_models():
9-
fiscal_year = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=2016)
9+
fiscal_year = mommy.make(
10+
"submissions.SubmissionAttributes", reporting_fiscal_year=2016, is_final_balances_for_fy=True
11+
)
12+
fiscal_year_2 = mommy.make(
13+
"submissions.SubmissionAttributes", reporting_fiscal_year=2016, is_final_balances_for_fy=False
14+
)
1015
top_tier_id = mommy.make("references.Agency", id=654, toptier_agency_id=987).toptier_agency_id
1116
top_tier = mommy.make("references.ToptierAgency", toptier_agency_id=top_tier_id)
1217
federal_id_awesome = mommy.make(
@@ -88,7 +93,7 @@ def financial_obligations_models():
8893
# Test to make sure False value is ignored in calculation
8994
mommy.make(
9095
"accounts.AppropriationAccountBalances",
91-
submission=fiscal_year,
96+
submission=fiscal_year_2,
9297
final_of_fy=False,
9398
obligations_incurred_total_by_tas_cpe=200,
9499
treasury_account_identifier=id_awesome,

usaspending_api/accounts/tests/test_financial_balances.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
@pytest.fixture
88
def financial_balances_models():
9-
sub = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=2016, toptier_code="abc")
9+
sub = mommy.make(
10+
"submissions.SubmissionAttributes",
11+
reporting_fiscal_year=2016,
12+
toptier_code="abc",
13+
is_final_balances_for_fy=True,
14+
)
1015
agency1_toptier = mommy.make("references.TopTierAgency", toptier_agency_id=123, toptier_code="abc")
1116
mommy.make("references.Agency", id=456, toptier_agency_id=123)
1217
tas1 = mommy.make("accounts.TreasuryAppropriationAccount", funding_toptier_agency=agency1_toptier)

usaspending_api/accounts/tests/test_tas_endpoints.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,24 @@
1313
def account_models():
1414
# Add submission data
1515
subm_2015_1 = mommy.make(
16-
"submissions.SubmissionAttributes", reporting_period_start=date(2014, 10, 1), reporting_fiscal_year=2015
16+
"submissions.SubmissionAttributes",
17+
reporting_period_start=date(2014, 10, 1),
18+
reporting_fiscal_year=2015,
1719
)
1820
subm_2015_2 = mommy.make(
19-
"submissions.SubmissionAttributes", reporting_period_start=date(2015, 8, 1), reporting_fiscal_year=2015
21+
"submissions.SubmissionAttributes",
22+
reporting_period_start=date(2015, 8, 1),
23+
reporting_fiscal_year=2015,
24+
is_final_balances_for_fy=True,
2025
)
2126
subm_2016_1 = mommy.make(
2227
"submissions.SubmissionAttributes", reporting_period_start=date(2016, 1, 1), reporting_fiscal_year=2016
2328
)
2429
subm_2016_2 = mommy.make(
25-
"submissions.SubmissionAttributes", reporting_period_start=date(2016, 6, 1), reporting_fiscal_year=2016
30+
"submissions.SubmissionAttributes",
31+
reporting_period_start=date(2016, 6, 1),
32+
reporting_fiscal_year=2016,
33+
is_final_balances_for_fy=True,
2634
)
2735

2836
# add object classes

usaspending_api/accounts/views/federal_accounts_v2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class FiscalYearSnapshotFederalAccountsViewSet(APIView):
8787
@cache_response()
8888
def get(self, request, pk, fy=0, format=None):
8989
fy = int(fy) or SubmissionAttributes.latest_available_fy()
90-
queryset = AppropriationAccountBalances.final_objects.filter(
91-
treasury_account_identifier__federal_account_id=int(pk)
90+
queryset = AppropriationAccountBalances.objects.filter(
91+
submission__is_final_balances_for_fy=True, treasury_account_identifier__federal_account_id=int(pk)
9292
).filter(submission__reporting_fiscal_year=fy)
9393
queryset = queryset.aggregate(
9494
outlay=Sum("gross_outlay_amount_by_tas_cpe"),
@@ -130,8 +130,8 @@ def post(self, request, pk, format=None):
130130
nested_order = ""
131131
group_results = OrderedDict() # list of time_period objects ie {"fy": "2017", "quarter": "3"} : 1000
132132

133-
financial_account_queryset = AppropriationAccountBalances.final_objects.filter(
134-
treasury_account_identifier__federal_account_id=int(pk)
133+
financial_account_queryset = AppropriationAccountBalances.objects.filter(
134+
submission__is_final_balances_for_fy=True, treasury_account_identifier__federal_account_id=int(pk)
135135
)
136136
if group == "fy" or group == "fiscal_year":
137137

usaspending_api/accounts/views/federal_obligations.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ def get_queryset(self):
2929
if not funding_agency_id or not fiscal_year:
3030
raise InvalidParameterException("Missing required query parameters: fiscal_year & funding_agency_id")
3131

32-
# Using final_objects below ensures that we're only pulling the latest
33-
# set of financial information for each fiscal year
3432
queryset = (
35-
AppropriationAccountBalances.final_objects.filter(
33+
AppropriationAccountBalances.objects.filter(
3634
treasury_account_identifier__funding_toptier_agency__agency__id=funding_agency_id,
3735
submission__reporting_fiscal_year=fiscal_year,
36+
submission__is_final_balances_for_fy=True,
3837
)
3938
.annotate(
4039
account_title=F("treasury_account_identifier__federal_account__account_title"),

usaspending_api/accounts/views/financial_balances.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ def get_queryset(self, pk=None):
4747
active_fiscal_year = submission.reporting_fiscal_year
4848
active_fiscal_quarter = submission.fiscal_quarter
4949

50-
# using final_objects ensures that we're only pulling the latest
51-
# set of financial information for each fiscal year
5250
queryset = (
53-
AppropriationAccountBalances.final_objects.all()
54-
.filter(
51+
AppropriationAccountBalances.objects.filter(
5552
submission__reporting_fiscal_year=active_fiscal_year,
5653
submission__reporting_fiscal_quarter=active_fiscal_quarter,
5754
treasury_account_identifier__funding_toptier_agency=toptier_agency,
55+
submission__is_final_balances_for_fy=True,
5856
)
5957
.annotate(fiscal_year=F("submission__reporting_fiscal_year"))
6058
.values("fiscal_year")

usaspending_api/accounts/views/financial_spending.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,14 @@ def get_queryset(self):
5151
active_fiscal_year = submission.reporting_fiscal_year
5252
active_fiscal_quarter = submission.fiscal_quarter
5353

54-
# using final_objects ensures that we're only pulling the latest
55-
# set of financial information for each fiscal year
5654
# Special case: major object class name for class 00 should be reported
5755
# as Unknown Object Type, overriding actual value in database
5856
queryset = (
59-
FinancialAccountsByProgramActivityObjectClass.final_objects.all()
60-
.filter(
57+
FinancialAccountsByProgramActivityObjectClass.objects.filter(
6158
submission__reporting_fiscal_year=active_fiscal_year,
6259
submission__reporting_fiscal_quarter=active_fiscal_quarter,
6360
treasury_account__funding_toptier_agency=toptier_agency,
61+
submission__is_final_balances_for_fy=True,
6462
)
6563
.annotate(
6664
major_object_class_name=Case(
@@ -119,9 +117,9 @@ def get_queryset(self):
119117
active_fiscal_year = submission.reporting_fiscal_year
120118
active_fiscal_quarter = submission.fiscal_quarter
121119

122-
# using final_objects below ensures that we're only pulling the latest
123-
# set of financial information for each fiscal year
124-
queryset = FinancialAccountsByProgramActivityObjectClass.final_objects.all()
120+
queryset = FinancialAccountsByProgramActivityObjectClass.objects.filter(
121+
submission__is_final_balances_for_fy=True
122+
)
125123
# get the incoming agency's toptier agency, because that's what we'll
126124
# need to filter on
127125
# (used filter() instead of get() b/c we likely don't want to raise an

usaspending_api/accounts/views/tas.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TASBalancesAggregate(FilterQuerysetMixin, AggregateQuerysetMixin, CachedDe
2020
serializer_class = AggregateSerializer
2121

2222
def get_queryset(self):
23-
queryset = AppropriationAccountBalances.final_objects.all()
23+
queryset = AppropriationAccountBalances.objects.filter(submission__is_final_balances_for_fy=True)
2424
queryset = self.filter_records(self.request, queryset=queryset)
2525
queryset = self.aggregate(self.request, queryset=queryset)
2626
queryset = self.order_records(self.request, queryset=queryset)
@@ -50,7 +50,9 @@ class TASCategoryAggregate(FilterQuerysetMixin, AggregateQuerysetMixin, CachedDe
5050
serializer_class = AggregateSerializer
5151

5252
def get_queryset(self):
53-
queryset = FinancialAccountsByProgramActivityObjectClass.final_objects.all()
53+
queryset = FinancialAccountsByProgramActivityObjectClass.objects.filter(
54+
submission__is_final_balances_for_fy=True
55+
)
5456
queryset = self.filter_records(self.request, queryset=queryset)
5557
queryset = self.aggregate(self.request, queryset=queryset)
5658
queryset = self.order_records(self.request, queryset=queryset)

0 commit comments

Comments
 (0)