Skip to content

Commit

Permalink
Merge pull request #1202 from fecgov/patch-1774
Browse files Browse the repository at this point in the history
1774 Limit recalculating reports to committee account
  • Loading branch information
toddlees authored Nov 14, 2024
2 parents d626460 + 9c8e953 commit 02e0350
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 41 deletions.
50 changes: 9 additions & 41 deletions django-backend/fecfiler/web_services/summary/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from enum import Enum
from celery import shared_task
from fecfiler.reports.models import Report, FORMS_TO_CALCULATE
from django.db.models import Q
from .summary import SummaryService
import uuid
import structlog
Expand All @@ -20,22 +19,6 @@ def __str__(self):
return str(self.value)


def get_reports_to_calculate_by_coverage_date(primary_report):
if not hasattr(primary_report, "coverage_from_date"):
return primary_report

report_year = primary_report.coverage_from_date.year
reports_to_recalculate = Report.objects.filter(
~Q(calculation_status=CalculationState.SUCCEEDED),
coverage_from_date__year=report_year,
coverage_through_date__lte=primary_report.coverage_through_date,
).order_by("coverage_through_date")

if len(reports_to_recalculate) > 0:
return reports_to_recalculate
return primary_report


@shared_task
def calculate_summary(report_id):
try:
Expand All @@ -47,7 +30,7 @@ def calculate_summary(report_id):
return primary_report.id

reports_to_recalculate = Report.objects.filter(
form_3x__isnull=False
committee_account=primary_report.committee_account, form_3x__isnull=False
).order_by("coverage_through_date")
calculation_token = uuid.uuid4()
reports_to_recalculate.update(
Expand Down Expand Up @@ -93,9 +76,7 @@ def calculate_summary(report_id):
report.form_3x.L11b_political_party_committees_period = a.get("line_11b", 0)
report.form_3x.L11b_political_party_committees_ytd = b.get("line_11b", 0)
# line 11c
report.form_3x.L11c_other_political_committees_pacs_period = a.get(
"line_11c", 0
)
report.form_3x.L11c_other_political_committees_pacs_period = a.get("line_11c", 0)
report.form_3x.L11c_other_political_committees_pacs_ytd = b.get("line_11c", 0)
# line 11d
report.form_3x.L11d_total_contributions_period = a.get("line_11d", 0)
Expand Down Expand Up @@ -137,16 +118,12 @@ def calculate_summary(report_id):
report.form_3x.L18b_transfers_from_nonfederal_levin_h5_period = a.get(
"line_18b", 0
) # noqa: E501
report.form_3x.L18b_transfers_from_nonfederal_levin_h5_ytd = b.get(
"line_18b", 0
)
report.form_3x.L18b_transfers_from_nonfederal_levin_h5_ytd = b.get("line_18b", 0)
# line 18c
report.form_3x.L18c_total_nonfederal_transfers_18a_18b_period = a.get(
"line_18c", 0
) # noqa: E501
report.form_3x.L18c_total_nonfederal_transfers_18a_18b_ytd = b.get(
"line_18c", 0
)
report.form_3x.L18c_total_nonfederal_transfers_18a_18b_ytd = b.get("line_18c", 0)
# line 19
report.form_3x.L19_total_receipts_period = a.get("line_19", 0)
report.form_3x.L19_total_receipts_ytd = b.get("line_19", 0)
Expand Down Expand Up @@ -232,13 +209,9 @@ def calculate_summary(report_id):
report.form_3x.L30b_nonallocable_fed_election_activity_period = a.get(
"line_30b", 0
) # noqa: E501
report.form_3x.L30b_nonallocable_fed_election_activity_ytd = b.get(
"line_30b", 0
)
report.form_3x.L30b_nonallocable_fed_election_activity_ytd = b.get("line_30b", 0)
# line 30c
report.form_3x.L30c_total_federal_election_activity_period = a.get(
"line_30c", 0
)
report.form_3x.L30c_total_federal_election_activity_period = a.get("line_30c", 0)
report.form_3x.L30c_total_federal_election_activity_ytd = b.get("line_30c", 0)
# line 31
report.form_3x.L31_total_disbursements_period = a.get("line_31", 0)
Expand All @@ -259,13 +232,9 @@ def calculate_summary(report_id):
report.form_3x.L36_total_federal_operating_expenditures_period = a.get(
"line_36", 0
) # noqa: E501
report.form_3x.L36_total_federal_operating_expenditures_ytd = b.get(
"line_36", 0
)
report.form_3x.L36_total_federal_operating_expenditures_ytd = b.get("line_36", 0)
# line 37
report.form_3x.L37_offsets_to_operating_expenditures_period = a.get(
"line_37", 0
)
report.form_3x.L37_offsets_to_operating_expenditures_period = a.get("line_37", 0)
report.form_3x.L37_offsets_to_operating_expenditures_ytd = b.get("line_37", 0)
# line 38
report.form_3x.L38_net_operating_expenditures_period = a.get("line_38", 0)
Expand All @@ -283,8 +252,7 @@ def calculate_summary(report_id):
Report.objects.filter(
id=report.id, calculation_token=calculation_token
).update(
calculation_status=CalculationState.SUCCEEDED,
calculation_token=None
calculation_status=CalculationState.SUCCEEDED, calculation_token=None
)
)

Expand Down
26 changes: 26 additions & 0 deletions django-backend/fecfiler/web_services/summary/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,29 @@ def test_report_group_recalculation_year_to_year(self):
next_year_report.form_3x.L8_cash_on_hand_at_close_period, # noqa: E501
Decimal("12661.53"),
)

def test_only_update_committees_reports(self):
other_committee = CommitteeAccount.objects.create(committee_id="C00000001")
create_committee_view(other_committee.id)
other_committees_f3x = create_form3x(
other_committee,
datetime.strptime("2024-01-01", "%Y-%m-%d").date(),
datetime.strptime("2024-02-01", "%Y-%m-%d").date(),
)
f3x = create_form3x(
self.committee,
datetime.strptime("2024-01-01", "%Y-%m-%d").date(),
datetime.strptime("2024-02-01", "%Y-%m-%d").date(),
)
other_f3x = create_form3x(
self.committee,
datetime.strptime("2023-01-01", "%Y-%m-%d").date(),
datetime.strptime("2023-02-01", "%Y-%m-%d").date(),
)
calculate_summary(f3x.id)
f3x.refresh_from_db()
other_committees_f3x.refresh_from_db()
other_f3x.refresh_from_db()
self.assertIsNone(other_committees_f3x.calculation_status)
self.assertEqual(f3x.calculation_status, CalculationState.SUCCEEDED.value)
self.assertEqual(other_f3x.calculation_status, CalculationState.SUCCEEDED.value)

0 comments on commit 02e0350

Please sign in to comment.