Skip to content

Commit

Permalink
Added logic to prevent finding reference year and audit year mismatch…
Browse files Browse the repository at this point in the history
… in findings workbook
  • Loading branch information
sambodeme committed Jan 10, 2025
1 parent 67b4035 commit 0c59326
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
47 changes: 47 additions & 0 deletions backend/audit/intakelib/checks/check_finding_reference_year.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import logging
from django.core.exceptions import ValidationError
from audit.intakelib.intermediate_representation import (
get_range_by_name,
)
from audit.intakelib.common import (
get_message,
build_cell_error_tuple,
)

from audit.context import get_sac_from_context
from audit.intakelib.common.util import get_range_start_row

logger = logging.getLogger(__name__)


# DESCRIPTION
# Finding references should be in 20##-### format where the first four
# digits match the audit_year.


def finding_reference_year(ir, is_gsa_migration=False):
references = get_range_by_name(ir, "reference_number")
range_start = int(get_range_start_row(references))
errors = []
if is_gsa_migration:
return errors
sac = get_sac_from_context()
audit_date = sac.general_information["auditee_fiscal_period_end"]
audit_year = int(audit_date.split("-")[0])
for index, reference in enumerate(references["values"]):
year = int(reference.split("-")[0])
if audit_year != year:
errors.append(
build_cell_error_tuple(
ir,
references,
index,
get_message("check_invalid_finding_reference_year").format(
reference, index + range_start, audit_year
),
)
)

if len(errors) > 0:
logger.info("Raising a validation error.")
raise ValidationError(errors)
2 changes: 2 additions & 0 deletions backend/audit/intakelib/checks/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from .check_findings_grid_validation import findings_grid_validation
from .check_finding_prior_references_pattern import prior_references_pattern
from .check_finding_reference_pattern import finding_reference_pattern
from .check_finding_reference_year import finding_reference_year
from .check_aln_prefix_pattern import aln_agency_prefix

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -111,6 +112,7 @@
award_references_pattern,
prior_references_pattern,
finding_reference_pattern,
finding_reference_year,
no_repeat_findings,
findings_grid_validation,
# See ticket #4385 for more information on why this check is disabled
Expand Down
1 change: 1 addition & 0 deletions backend/audit/intakelib/common/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"check_aln_three_digit_extension_invalid": "The three digit extension should follow one of these formats: ###, RD#, or U##, where # represents a number",
"check_prior_references_invalid": "Prior references must be <b>N/A</b> or a comma-separated list of values in the format <b>20##-###</b>, for example, <b>2019-001, 2019-002</b>",
"check_finding_reference_invalid": "Finding references must be in the format <b>20##-###</b> where the first four digits are a year after 2010, for example, <b>2019-001, 2019-002</b>",
"check_invalid_finding_reference_year": "The reference year in the finding reference <b>{}</b> declared in row {} does not match the audit year <b>{}</b>",
"check_award_references_invalid": "Combining award references of 4 and 5-digit lengths is not allowed. If needed, zero-pad this number to make it 5 digits",
"check_aln_prefix_invalid": "The federal agency prefix should be a two-digit value, for example, <b>10</b>",
"check_additional_award_identification_present": "Missing additional award identification",
Expand Down
13 changes: 7 additions & 6 deletions backend/audit/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
)
from audit.utils import FORM_SECTION_HANDLERS

from audit.context import set_sac_to_context
from dissemination.remove_workbook_artifacts import remove_workbook_artifacts
from dissemination.file_downloads import get_download_url, get_filename
from dissemination.models import General
Expand Down Expand Up @@ -233,14 +234,14 @@ def post(self, request, *_args, **kwargs):
and "auditee_uei" in sac.general_information
):
auditee_uei = sac.general_information["auditee_uei"]
with set_sac_to_context(sac):
audit_data = self._extract_and_validate_data(
form_section, excel_file, auditee_uei
)

audit_data = self._extract_and_validate_data(
form_section, excel_file, auditee_uei
)

self._save_audit_data(sac, form_section, audit_data)
self._save_audit_data(sac, form_section, audit_data)

return redirect("/")
return redirect("/")

except SingleAuditChecklist.DoesNotExist as err:
logger.warning("no SingleAuditChecklist found with report ID %s", report_id)
Expand Down

0 comments on commit 0c59326

Please sign in to comment.