Skip to content

Commit

Permalink
[DEV-6910] Fixes 'amount' calculation to match new tbr formula
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Collins committed Feb 24, 2021
1 parent c803f8e commit 96fa00c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
1 change: 0 additions & 1 deletion usaspending_api/disaster/tests/fixtures/overview_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def calculate_values(input_dict):
)

return {
"total_budgetary_resources_cpe": to_decimal(input_dict["total_budgetary_resources_cpe"]),
"total_budgetary_resources": to_decimal(TOTAL_BUDGETARY_RESOURCES),
"total_obligations": to_decimal(TOTAL_OBLIGATIONS),
"total_outlays": to_decimal(TOTAL_OUTLAYS),
Expand Down
28 changes: 11 additions & 17 deletions usaspending_api/disaster/tests/integration/test_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@

OVERVIEW_URL = "/api/v2/disaster/overview/"

BASIC_FUNDING = [{"amount": Decimal("0.20"), "def_code": "M"}]


@pytest.mark.django_db
def test_basic_data_set(client, monkeypatch, helpers, defc_codes, basic_ref_data, early_gtas, basic_faba):
helpers.patch_datetime_now(monkeypatch, EARLY_YEAR, EARLY_MONTH, 25)
helpers.reset_dabs_cache()
resp = client.get(OVERVIEW_URL)
assert resp.data == {
"funding": BASIC_FUNDING,
"funding": [{"amount": EARLY_GTAS_CALCULATIONS["total_budgetary_resources"], "def_code": "M"}],
"total_budget_authority": EARLY_GTAS_CALCULATIONS["total_budgetary_resources"],
"spending": {
"award_obligations": Decimal("0.0"),
Expand Down Expand Up @@ -64,7 +62,7 @@ def test_exclude_gtas_for_incompleted_period(
helpers.patch_datetime_now(monkeypatch, EARLY_YEAR, LATE_MONTH, 25)
helpers.reset_dabs_cache()
resp = client.get(OVERVIEW_URL)
assert resp.data["funding"] == [{"amount": Decimal("0.2"), "def_code": "M"}]
assert resp.data["funding"] == [{"amount": EARLY_GTAS_CALCULATIONS["total_budgetary_resources"], "def_code": "M"}]
assert resp.data["total_budget_authority"] == EARLY_GTAS_CALCULATIONS["total_budgetary_resources"]
assert resp.data["spending"]["total_obligations"] == EARLY_GTAS_CALCULATIONS["total_obligations"]
assert resp.data["spending"]["total_outlays"] == EARLY_GTAS_CALCULATIONS["total_outlays"]
Expand Down Expand Up @@ -94,8 +92,8 @@ def test_summing_multiple_years(
resp = client.get(OVERVIEW_URL)
assert resp.data["funding"] == [
{
"amount": +YEAR_2_GTAS_CALCULATIONS["total_budgetary_resources_cpe"]
+ LATE_GTAS_CALCULATIONS["total_budgetary_resources_cpe"],
"amount": +YEAR_2_GTAS_CALCULATIONS["total_budgetary_resources"]
+ LATE_GTAS_CALCULATIONS["total_budgetary_resources"],
"def_code": "M",
}
]
Expand All @@ -122,8 +120,8 @@ def test_summing_period_and_quarterly_in_same_year(
resp = client.get(OVERVIEW_URL)
assert resp.data["funding"] == [
{
"amount": LATE_GTAS_CALCULATIONS["total_budgetary_resources_cpe"]
+ QUARTERLY_GTAS_CALCULATIONS["total_budgetary_resources_cpe"],
"amount": LATE_GTAS_CALCULATIONS["total_budgetary_resources"]
+ QUARTERLY_GTAS_CALCULATIONS["total_budgetary_resources"],
"def_code": "M",
}
]
Expand All @@ -141,9 +139,7 @@ def test_ignore_gtas_not_yet_revealed(
helpers.patch_datetime_now(monkeypatch, LATE_YEAR, EARLY_MONTH - 1, 25)
helpers.reset_dabs_cache()
resp = client.get(OVERVIEW_URL)
assert resp.data["funding"] == [
{"amount": LATE_GTAS_CALCULATIONS["total_budgetary_resources_cpe"], "def_code": "M"}
]
assert resp.data["funding"] == [{"amount": LATE_GTAS_CALCULATIONS["total_budgetary_resources"], "def_code": "M"}]
assert resp.data["total_budget_authority"] == LATE_GTAS_CALCULATIONS["total_budgetary_resources"]
assert resp.data["spending"]["total_obligations"] == LATE_GTAS_CALCULATIONS["total_obligations"]
assert resp.data["spending"]["total_outlays"] == LATE_GTAS_CALCULATIONS["total_outlays"]
Expand All @@ -156,17 +152,15 @@ def test_ignore_funding_for_unselected_defc(
helpers.patch_datetime_now(monkeypatch, LATE_YEAR, EARLY_MONTH, 25)
helpers.reset_dabs_cache()
resp = client.get(OVERVIEW_URL + "?def_codes=M,A")
assert resp.data["funding"] == [
{"amount": YEAR_2_GTAS_CALCULATIONS["total_budgetary_resources_cpe"], "def_code": "M"}
]
assert resp.data["funding"] == [{"amount": YEAR_2_GTAS_CALCULATIONS["total_budgetary_resources"], "def_code": "M"}]
assert resp.data["total_budget_authority"] == YEAR_2_GTAS_CALCULATIONS["total_budgetary_resources"]
assert resp.data["spending"]["total_obligations"] == YEAR_2_GTAS_CALCULATIONS["total_obligations"]
assert resp.data["spending"]["total_outlays"] == YEAR_2_GTAS_CALCULATIONS["total_outlays"]

resp = client.get(OVERVIEW_URL + "?def_codes=M,N")
assert resp.data["funding"] == [
{"amount": Decimal("0.32"), "def_code": "M"},
{"amount": Decimal("0.32"), "def_code": "N"},
{"amount": YEAR_2_GTAS_CALCULATIONS["total_budgetary_resources"], "def_code": "M"},
{"amount": YEAR_2_GTAS_CALCULATIONS["total_budgetary_resources"], "def_code": "N"},
]
assert resp.data["total_budget_authority"] == YEAR_2_GTAS_CALCULATIONS["total_budgetary_resources"] * 2
assert resp.data["spending"]["total_obligations"] == YEAR_2_GTAS_CALCULATIONS["total_obligations"] * 2
Expand All @@ -179,7 +173,7 @@ def test_adds_budget_values(client, monkeypatch, helpers, defc_codes, basic_ref_
helpers.reset_dabs_cache()
resp = client.get(OVERVIEW_URL)
assert resp.data["funding"] == [
{"amount": OTHER_BUDGET_AUTHORITY_GTAS_CALCULATIONS["total_budgetary_resources_cpe"], "def_code": "M"}
{"amount": OTHER_BUDGET_AUTHORITY_GTAS_CALCULATIONS["total_budgetary_resources"], "def_code": "M"}
]
assert resp.data["total_budget_authority"] == OTHER_BUDGET_AUTHORITY_GTAS_CALCULATIONS["total_budgetary_resources"]
assert resp.data["spending"]["total_obligations"] == OTHER_BUDGET_AUTHORITY_GTAS_CALCULATIONS["total_obligations"]
Expand Down
21 changes: 9 additions & 12 deletions usaspending_api/disaster/v2/views/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,19 @@ def funding(self):
.values("disaster_emergency_fund_code")
.annotate(
def_code=F("disaster_emergency_fund_code"),
amount=Sum("total_budgetary_resources_cpe"),
total_budget_authority=(
Sum("total_budgetary_resources_cpe") - (
Sum("budget_authority_unobligated_balance_brought_forward_cpe") +
Sum("deobligations_or_recoveries_or_refunds_from_prior_year_cpe") +
Sum("prior_year_paid_obligation_recoveries")
amount=(
Sum("total_budgetary_resources_cpe")
- (
Sum("budget_authority_unobligated_balance_brought_forward_cpe")
+ Sum("deobligations_or_recoveries_or_refunds_from_prior_year_cpe")
+ Sum("prior_year_paid_obligation_recoveries")
)
)
),
)
.values("def_code", "amount", "total_budget_authority")
.values("def_code", "amount")
)

total_budget_authority = self.sum_values(funding, "total_budget_authority")

for entry in funding:
del entry["total_budget_authority"]
total_budget_authority = self.sum_values(funding, "amount")

return funding, total_budget_authority

Expand Down

0 comments on commit 96fa00c

Please sign in to comment.