From 96fa00c0a027e88b46ec9d5ea8bca13ec48285e4 Mon Sep 17 00:00:00 2001 From: Wil Collins Date: Wed, 24 Feb 2021 15:02:50 -0500 Subject: [PATCH] [DEV-6910] Fixes 'amount' calculation to match new tbr formula --- .../disaster/tests/fixtures/overview_data.py | 1 - .../tests/integration/test_overview.py | 28 ++++++++----------- usaspending_api/disaster/v2/views/overview.py | 21 ++++++-------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/usaspending_api/disaster/tests/fixtures/overview_data.py b/usaspending_api/disaster/tests/fixtures/overview_data.py index 82fa9a1beb..16a30776f5 100644 --- a/usaspending_api/disaster/tests/fixtures/overview_data.py +++ b/usaspending_api/disaster/tests/fixtures/overview_data.py @@ -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), diff --git a/usaspending_api/disaster/tests/integration/test_overview.py b/usaspending_api/disaster/tests/integration/test_overview.py index 639c3da430..d5e4fdbb08 100644 --- a/usaspending_api/disaster/tests/integration/test_overview.py +++ b/usaspending_api/disaster/tests/integration/test_overview.py @@ -15,8 +15,6 @@ 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): @@ -24,7 +22,7 @@ def test_basic_data_set(client, monkeypatch, helpers, defc_codes, basic_ref_data 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"), @@ -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"] @@ -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", } ] @@ -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", } ] @@ -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"] @@ -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 @@ -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"] diff --git a/usaspending_api/disaster/v2/views/overview.py b/usaspending_api/disaster/v2/views/overview.py index 7fa34c4ee9..27ec3330cc 100644 --- a/usaspending_api/disaster/v2/views/overview.py +++ b/usaspending_api/disaster/v2/views/overview.py @@ -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