Skip to content

Commit c738c24

Browse files
authored
Merge pull request #3043 from fedspendingtransparency/staging
Sprint 128 Production Deploy
2 parents b177160 + 0e01bf8 commit c738c24

File tree

73 files changed

+1514
-515
lines changed

Some content is hidden

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

73 files changed

+1514
-515
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ RUN python3 -m pip install -r requirements/requirements.txt
4040
##### Copy the rest of the project files into the container
4141
COPY . /dockermount
4242

43-
ENV PYTHONUNBUFFERED=0
43+
##### Ensure Python STDOUT gets sent to container logs
44+
ENV PYTHONUNBUFFERED=1

requirements/requirements-app.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ attrs==20.*
44
boto3==1.16.*
55
certifi==2020.12.5
66
dataclasses-json==0.5.*
7-
ddtrace==0.37.1
7+
ddtrace==0.46.0
88
dj-database-url==0.5.0
99
django-cors-headers==2.5.3
1010
django-debug-toolbar==3.2

usaspending_api/accounts/v2/filters/account_download.py

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,22 @@ def get_submission_filter(account_type, filters):
129129
)
130130

131131
submission_filter = Q(
132-
outlay_filter & (Q(gross_outlay_amount_by_award_cpe__gt=0) | Q(gross_outlay_amount_by_award_cpe__lt=0))
132+
outlay_filter
133+
& Q(
134+
Q(gross_outlay_amount_by_award_cpe__gt=0)
135+
| Q(gross_outlay_amount_by_award_cpe__lt=0)
136+
| Q(ussgl487200_down_adj_pri_ppaid_undel_orders_oblig_refund_cpe__gt=0)
137+
| Q(ussgl487200_down_adj_pri_ppaid_undel_orders_oblig_refund_cpe__lt=0)
138+
| Q(ussgl497200_down_adj_pri_paid_deliv_orders_oblig_refund_cpe__gt=0)
139+
| Q(ussgl497200_down_adj_pri_paid_deliv_orders_oblig_refund_cpe__lt=0)
140+
)
133141
) | Q(obligation_filter & Q(Q(transaction_obligated_amount__gt=0) | Q(transaction_obligated_amount__lt=0)))
134142

135143
return submission_filter
136144

137145

138-
def generate_gross_outlay_amount_derived_field(filters, account_type):
139-
column_name = {
140-
"account_balances": "gross_outlay_amount_by_tas_cpe",
141-
"object_class_program_activity": "gross_outlay_amount_by_program_object_class_cpe",
142-
"award_financial": "gross_outlay_amount_by_award_cpe",
143-
}[account_type]
144-
146+
def _generate_closed_period_for_derived_field(filters, column_name):
145147
filter_year = filters.get("fy")
146-
147148
closed_periods = get_last_closed_periods_per_year()
148149

149150
q = Q()
@@ -163,6 +164,26 @@ def generate_gross_outlay_amount_derived_field(filters, account_type):
163164
return Cast(Value(None), DecimalField(max_digits=23, decimal_places=2))
164165

165166

167+
def generate_ussgl487200_derived_field(filters):
168+
column_name = "ussgl487200_down_adj_pri_ppaid_undel_orders_oblig_refund_cpe"
169+
return _generate_closed_period_for_derived_field(filters, column_name)
170+
171+
172+
def generate_ussgl497200_derived_field(filters):
173+
column_name = "ussgl497200_down_adj_pri_paid_deliv_orders_oblig_refund_cpe"
174+
return _generate_closed_period_for_derived_field(filters, column_name)
175+
176+
177+
def generate_gross_outlay_amount_derived_field(filters, account_type):
178+
column_name = {
179+
"account_balances": "gross_outlay_amount_by_tas_cpe",
180+
"object_class_program_activity": "gross_outlay_amount_by_program_object_class_cpe",
181+
"award_financial": "gross_outlay_amount_by_award_cpe",
182+
}[account_type]
183+
184+
return _generate_closed_period_for_derived_field(filters, column_name)
185+
186+
166187
def generate_treasury_account_query(queryset, account_type, tas_id, filters):
167188
""" Derive necessary fields for a treasury account-grouped query """
168189
derived_fields = {
@@ -176,6 +197,19 @@ def generate_treasury_account_query(queryset, account_type, tas_id, filters):
176197
}
177198

178199
lmd = "last_modified_date" + NAMING_CONFLICT_DISCRIMINATOR
200+
201+
if account_type != "account_balances":
202+
derived_fields.update(
203+
{
204+
"downward_adj_prior_yr_ppaid_undeliv_orders_oblig_refunds_cpe": Sum(
205+
generate_ussgl487200_derived_field(filters)
206+
),
207+
"downward_adj_prior_yr_paid_delivered_orders_oblig_refunds_cpe": Sum(
208+
generate_ussgl497200_derived_field(filters)
209+
),
210+
}
211+
)
212+
179213
if account_type == "award_financial":
180214
# Separating out last_modified_date like this prevents unnecessary grouping in the full File
181215
# C TAS download. Keeping it as MAX caused grouping on every single column in the SQL statement.
@@ -201,6 +235,17 @@ def generate_federal_account_query(queryset, account_type, tas_id, filters):
201235
"gross_outlay_amount_fyb_to_period_end": Sum(generate_gross_outlay_amount_derived_field(filters, account_type)),
202236
}
203237

238+
if account_type != "account_balances":
239+
derived_fields.update(
240+
{
241+
"downward_adj_prior_yr_ppaid_undeliv_orders_oblig_refunds_cpe": Sum(
242+
generate_ussgl487200_derived_field(filters)
243+
),
244+
"downward_adj_prior_yr_paid_delivered_orders_oblig_refunds_cpe": Sum(
245+
generate_ussgl497200_derived_field(filters)
246+
),
247+
}
248+
)
204249
if account_type == "award_financial":
205250
derived_fields = award_financial_derivations(derived_fields)
206251

usaspending_api/agency/tests/integration/conftest.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,53 @@
66

77
@pytest.fixture
88
def agency_account_data():
9+
dabs = mommy.make("submissions.DABSSubmissionWindowSchedule", submission_reveal_date="2020-10-09")
10+
911
ta1 = mommy.make("references.ToptierAgency", toptier_code="007")
1012
ta2 = mommy.make("references.ToptierAgency", toptier_code="008")
1113
ta3 = mommy.make("references.ToptierAgency", toptier_code="009")
1214
ta4 = mommy.make("references.ToptierAgency", toptier_code="010")
15+
16+
mommy.make("references.Agency", id=1, toptier_flag=True, toptier_agency=ta1)
17+
mommy.make("references.Agency", id=2, toptier_flag=True, toptier_agency=ta2)
18+
mommy.make("references.Agency", id=3, toptier_flag=True, toptier_agency=ta3)
19+
mommy.make("references.Agency", id=4, toptier_flag=True, toptier_agency=ta4)
20+
1321
sub1 = mommy.make(
14-
"submissions.SubmissionAttributes", reporting_fiscal_year=current_fiscal_year(), is_final_balances_for_fy=True
22+
"submissions.SubmissionAttributes",
23+
reporting_fiscal_year=current_fiscal_year(),
24+
toptier_code=ta1.toptier_code,
25+
is_final_balances_for_fy=True,
26+
submission_window_id=dabs.id,
27+
)
28+
sub2 = mommy.make(
29+
"submissions.SubmissionAttributes",
30+
reporting_fiscal_year=2017,
31+
toptier_code=ta2.toptier_code,
32+
is_final_balances_for_fy=True,
33+
submission_window_id=dabs.id,
34+
)
35+
sub3 = mommy.make(
36+
"submissions.SubmissionAttributes",
37+
reporting_fiscal_year=2018,
38+
toptier_code=ta3.toptier_code,
39+
is_final_balances_for_fy=True,
40+
submission_window_id=dabs.id,
41+
)
42+
sub4 = mommy.make(
43+
"submissions.SubmissionAttributes",
44+
reporting_fiscal_year=2019,
45+
toptier_code=ta4.toptier_code,
46+
is_final_balances_for_fy=True,
47+
submission_window_id=dabs.id,
48+
)
49+
sub5 = mommy.make(
50+
"submissions.SubmissionAttributes",
51+
reporting_fiscal_year=2016,
52+
toptier_code=ta1.toptier_code,
53+
is_final_balances_for_fy=True,
54+
submission_window_id=dabs.id,
1555
)
16-
sub2 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=2017, is_final_balances_for_fy=True)
17-
sub3 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=2018, is_final_balances_for_fy=True)
18-
sub4 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=2019, is_final_balances_for_fy=True)
19-
sub5 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=2016, is_final_balances_for_fy=True)
2056
fa1 = mommy.make("accounts.FederalAccount", federal_account_code="001-0000", account_title="FA 1")
2157
fa2 = mommy.make("accounts.FederalAccount", federal_account_code="002-0000", account_title="FA 2")
2258
fa3 = mommy.make("accounts.FederalAccount", federal_account_code="003-0000", account_title="FA 3")

usaspending_api/agency/tests/integration/test_agency.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def agency_data():
3434
mommy.make("accounts.AppropriationAccountBalances", treasury_account_identifier=tas1)
3535
mommy.make("accounts.AppropriationAccountBalances", treasury_account_identifier=tas2)
3636
mommy.make("awards.TransactionNormalized", awarding_agency=a1, fiscal_year=current_fiscal_year())
37+
dabs = mommy.make("submissions.DABSSubmissionWindowSchedule", submission_reveal_date="2020-10-09")
38+
mommy.make("submissions.SubmissionAttributes", toptier_code=ta1.toptier_code, submission_window_id=dabs.id)
39+
mommy.make("submissions.SubmissionAttributes", toptier_code=ta2.toptier_code, submission_window_id=dabs.id)
3740

3841

3942
@pytest.mark.django_db

usaspending_api/agency/tests/integration/test_agency_budgetary_resources.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,48 @@
1313

1414
@pytest.fixture
1515
def data_fixture():
16+
dabs = mommy.make("submissions.DABSSubmissionWindowSchedule", submission_reveal_date="2020-10-09")
1617
ta1 = mommy.make("references.ToptierAgency", toptier_code="001")
1718
ta2 = mommy.make("references.ToptierAgency", toptier_code="002")
19+
mommy.make("references.Agency", toptier_flag=True, toptier_agency=ta1)
20+
mommy.make("references.Agency", toptier_flag=True, toptier_agency=ta2)
1821
tas1 = mommy.make("accounts.TreasuryAppropriationAccount", funding_toptier_agency=ta1)
1922
tas2 = mommy.make("accounts.TreasuryAppropriationAccount", funding_toptier_agency=ta2)
20-
sa1_3 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=FY, reporting_fiscal_period=3)
21-
sa1_6 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=FY, reporting_fiscal_period=6)
22-
sa1_9 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=FY, reporting_fiscal_period=9)
23-
sa1_12 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=FY, reporting_fiscal_period=12)
24-
sa2_12 = mommy.make("submissions.SubmissionAttributes", reporting_fiscal_year=PRIOR_FY, reporting_fiscal_period=12)
23+
sa1_3 = mommy.make(
24+
"submissions.SubmissionAttributes",
25+
reporting_fiscal_year=FY,
26+
reporting_fiscal_period=3,
27+
submission_window_id=dabs.id,
28+
toptier_code=ta1.toptier_code,
29+
)
30+
sa1_6 = mommy.make(
31+
"submissions.SubmissionAttributes",
32+
reporting_fiscal_year=FY,
33+
reporting_fiscal_period=6,
34+
submission_window_id=dabs.id,
35+
toptier_code=ta1.toptier_code,
36+
)
37+
sa1_9 = mommy.make(
38+
"submissions.SubmissionAttributes",
39+
reporting_fiscal_year=FY,
40+
reporting_fiscal_period=9,
41+
submission_window_id=dabs.id,
42+
toptier_code=ta1.toptier_code,
43+
)
44+
sa1_12 = mommy.make(
45+
"submissions.SubmissionAttributes",
46+
reporting_fiscal_year=FY,
47+
reporting_fiscal_period=12,
48+
submission_window_id=dabs.id,
49+
toptier_code=ta1.toptier_code,
50+
)
51+
sa2_12 = mommy.make(
52+
"submissions.SubmissionAttributes",
53+
reporting_fiscal_year=PRIOR_FY,
54+
reporting_fiscal_period=12,
55+
submission_window_id=dabs.id,
56+
toptier_code=ta2.toptier_code,
57+
)
2558

2659
mommy.make(
2760
"accounts.AppropriationAccountBalances",

usaspending_api/agency/v2/views/agency_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def fiscal_period(self):
6464

6565
@cached_property
6666
def toptier_agency(self):
67-
toptier_agency = ToptierAgency.objects.account_agencies().filter(toptier_code=self.toptier_code).first()
67+
toptier_agency = ToptierAgency.objects.filter(
68+
toptieragencypublisheddabsview__toptier_code=self.toptier_code
69+
).first()
6870
if not toptier_agency:
6971
raise NotFound(f"Agency with a toptier code of '{self.toptier_code}' does not exist")
7072
return toptier_agency
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 2.2.9 on 2021-03-15 19:46
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('awards', '0078_auto_20210211_2237'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveIndex(
14+
model_name='financialaccountsbyawards',
15+
name='faba_subid_awardkey_sums_idx',
16+
),
17+
migrations.AddIndex(
18+
model_name='financialaccountsbyawards',
19+
index=models.Index(condition=models.Q(disaster_emergency_fund__in=['L', 'M', 'N', 'O', 'P', 'U']), fields=['submission', 'distinct_award_key', 'piid', 'transaction_obligated_amount', 'gross_outlay_amount_by_award_cpe', 'ussgl497200_down_adj_pri_paid_deliv_orders_oblig_refund_cpe', 'ussgl487200_down_adj_pri_ppaid_undel_orders_oblig_refund_cpe'], name='faba_subid_awardkey_sums_idx'),
20+
),
21+
]

usaspending_api/awards/models/financial_accounts_by_awards.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Meta:
157157
"piid",
158158
"transaction_obligated_amount",
159159
"gross_outlay_amount_by_award_cpe",
160+
"ussgl497200_down_adj_pri_paid_deliv_orders_oblig_refund_cpe",
161+
"ussgl487200_down_adj_pri_ppaid_undel_orders_oblig_refund_cpe",
160162
],
161163
name="faba_subid_awardkey_sums_idx",
162164
condition=Q(disaster_emergency_fund__in=["L", "M", "N", "O", "P", "U"]),

usaspending_api/awards/tests/test_awards_v2.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,44 @@ def test_file_c_data(client, awards_and_transactions):
12181218
assert json.loads(resp.content.decode("utf-8"))["total_account_outlay"] == 110.0
12191219

12201220

1221+
def test_outlay_calculations(client, awards_and_transactions):
1222+
defc = mommy.make("references.DisasterEmergencyFundCode", code="L", group_name="covid_19")
1223+
mommy.make(
1224+
"submissions.DABSSubmissionWindowSchedule",
1225+
submission_fiscal_year=2019,
1226+
submission_fiscal_month=12,
1227+
is_quarter=True,
1228+
submission_reveal_date="2020-04-01",
1229+
period_start_date="2020-04-01",
1230+
)
1231+
mommy.make(
1232+
"submissions.SubmissionAttributes",
1233+
pk=4,
1234+
reporting_fiscal_period=12,
1235+
reporting_fiscal_year=2019,
1236+
reporting_period_end="2020-06-30",
1237+
quarter_format_flag=True,
1238+
is_final_balances_for_fy=True,
1239+
reporting_period_start="2020-04-01",
1240+
)
1241+
mommy.make(
1242+
"awards.FinancialAccountsByAwards",
1243+
award_id=1,
1244+
transaction_obligated_amount=10,
1245+
gross_outlay_amount_by_award_cpe=10,
1246+
ussgl487200_down_adj_pri_ppaid_undel_orders_oblig_refund_cpe=-1,
1247+
ussgl497200_down_adj_pri_paid_deliv_orders_oblig_refund_cpe=-2,
1248+
disaster_emergency_fund=defc,
1249+
submission_id=4,
1250+
)
1251+
resp = client.get("/api/v2/awards/1/")
1252+
assert resp.status_code == status.HTTP_200_OK
1253+
assert json.loads(resp.content.decode("utf-8"))["account_obligations_by_defc"] == [{"code": "L", "amount": 10.0}]
1254+
assert json.loads(resp.content.decode("utf-8"))["account_outlays_by_defc"] == [{"code": "L", "amount": 7.0}]
1255+
assert json.loads(resp.content.decode("utf-8"))["total_account_obligation"] == 10.0
1256+
assert json.loads(resp.content.decode("utf-8"))["total_account_outlay"] == 7.0
1257+
1258+
12211259
expected_response_asst = {
12221260
"id": 1,
12231261
"record_type": 111,

0 commit comments

Comments
 (0)