From 29db6805fc7cc66a7ecff3debb05171b7a5e3375 Mon Sep 17 00:00:00 2001 From: toddlees Date: Wed, 13 Nov 2024 12:50:53 -0500 Subject: [PATCH 1/2] limit recalculated reports to committee account --- .../fecfiler/web_services/summary/tasks.py | 49 ++++--------------- .../web_services/summary/test_tasks.py | 26 ++++++++++ 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/django-backend/fecfiler/web_services/summary/tasks.py b/django-backend/fecfiler/web_services/summary/tasks.py index 53d0c6f9ad..6a33269826 100644 --- a/django-backend/fecfiler/web_services/summary/tasks.py +++ b/django-backend/fecfiler/web_services/summary/tasks.py @@ -20,22 +20,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: @@ -47,7 +31,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( @@ -93,9 +77,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) @@ -137,16 +119,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) @@ -232,13 +210,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) @@ -259,13 +233,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) @@ -283,8 +253,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 ) ) diff --git a/django-backend/fecfiler/web_services/summary/test_tasks.py b/django-backend/fecfiler/web_services/summary/test_tasks.py index 099db057d6..10738af9c3 100644 --- a/django-backend/fecfiler/web_services/summary/test_tasks.py +++ b/django-backend/fecfiler/web_services/summary/test_tasks.py @@ -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) From 9c8e953dfb0c4024bd36ae90885a1d41dec5db2b Mon Sep 17 00:00:00 2001 From: toddlees Date: Wed, 13 Nov 2024 12:56:58 -0500 Subject: [PATCH 2/2] lint --- django-backend/fecfiler/web_services/summary/tasks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/django-backend/fecfiler/web_services/summary/tasks.py b/django-backend/fecfiler/web_services/summary/tasks.py index 6a33269826..7cc10396e6 100644 --- a/django-backend/fecfiler/web_services/summary/tasks.py +++ b/django-backend/fecfiler/web_services/summary/tasks.py @@ -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