Skip to content

Commit

Permalink
[DEV-6910] Moves TBR calculation to DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Collins committed Feb 24, 2021
1 parent 7de6bce commit c803f8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion usaspending_api/disaster/tests/fixtures/overview_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def calculate_values(input_dict):
TOTAL_BUDGETARY_RESOURCES = input_dict["total_budgetary_resources_cpe"] - (
input_dict["budget_authority_unobligated_balance_brought_forward_cpe"]
+ input_dict["deobligations_or_recoveries_or_refunds_from_prior_year_cpe"]
+ input_dict["anticipated_prior_year_obligation_recoveries"]
+ input_dict["prior_year_paid_obligation_recoveries"]
)
TOTAL_OBLIGATIONS = input_dict["obligations_incurred_total_cpe"] - (
input_dict["deobligations_or_recoveries_or_refunds_from_prior_year_cpe"]
Expand Down
25 changes: 10 additions & 15 deletions usaspending_api/disaster/v2/views/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,21 @@ def funding(self):
.annotate(
def_code=F("disaster_emergency_fund_code"),
amount=Sum("total_budgetary_resources_cpe"),
unobligated_balance=Sum("budget_authority_unobligated_balance_brought_forward_cpe"),
deobligations=Sum("deobligations_or_recoveries_or_refunds_from_prior_year_cpe"),
obligation_recoveries=Sum("prior_year_paid_obligation_recoveries"),
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")
)
)
)
.values("def_code", "amount", "unobligated_balance", "deobligations", "anticipated_recoveries")
.values("def_code", "amount", "total_budget_authority")
)

total_amount = self.sum_values(funding, "amount")
total_unobligated_balance = self.sum_values(funding, "unobligated_balance")
total_deobligations = self.sum_values(funding, "deobligations")
total_obligation_recoveries = self.sum_values(funding, "obligation_recoveries")

total_budget_authority = total_amount - (
total_unobligated_balance + total_deobligations + total_obligation_recoveries
)
total_budget_authority = self.sum_values(funding, "total_budget_authority")

for entry in funding:
del entry["unobligated_balance"]
del entry["deobligations"]
del entry["anticipated_recoveries"]
del entry["total_budget_authority"]

return funding, total_budget_authority

Expand Down

0 comments on commit c803f8e

Please sign in to comment.