Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sk/3715 missing firm names #3810

Merged
merged 19 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def check_for_gsa_migration_keyword(ir):
"contains_chart_or_table",
"is_minimis_rate_used",
"compliance_requirement",
"secondary_auditor_name",
"secondary_auditor_address_state",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .workbooklib.secondary_auditors import (
xform_address_state,
xform_cpafirmname,
)


Expand Down Expand Up @@ -30,3 +31,46 @@ def test_missing_address_state(self):
xform_address_state(secondary_auditors)

self.assertEqual(secondary_auditors[0].CPASTATE, settings.GSA_MIGRATION)


class TestXformCpaFirmName(SimpleTestCase):
class MockSecondaryAuditorHeader:
def __init__(
self,
DBKEY,
CPAFIRMNAME,
):
self.DBKEY = DBKEY
self.CPAFIRMNAME = CPAFIRMNAME

def _mock_secondaryauditor_header(self):
"""Returns a mock secondary_auditor with all necessary fields."""
return [
self.MockSecondaryAuditorHeader(
DBKEY="123456789",
CPAFIRMNAME="John Doe CPA Firm",
),
self.MockSecondaryAuditorHeader(
DBKEY="223456789",
CPAFIRMNAME="Jack C CPA Firm",
),
]

def test_valid_cpafirm(self):
"""Test that the function does not change the valid CPAFIRMNAME."""
secondary_auditors = self._mock_secondaryauditor_header()
cpas = secondary_auditors
xform_cpafirmname(secondary_auditors)
for index in range(len(secondary_auditors)):
self.assertEqual(
secondary_auditors[index].CPAFIRMNAME, cpas[index].CPAFIRMNAME
)

def test_blank_cpafirm(self):
"""Test that the function changes blank CPAFIRMNAME to GSA_MIGRATION."""
secondary_auditors = self._mock_secondaryauditor_header()
secondary_auditors[0].CPAFIRMNAME = ""
cpas = secondary_auditors
xform_cpafirmname(secondary_auditors)
self.assertEqual(secondary_auditors[0].CPAFIRMNAME, settings.GSA_MIGRATION)
self.assertEqual(secondary_auditors[1].CPAFIRMNAME, cpas[1].CPAFIRMNAME)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from ..models import ELECCPAS as Caps
from ..change_record import InspectionRecord
from audit.fixtures.excel import FORM_SECTIONS

from django.conf import settings
import openpyxl as pyxl

Expand Down Expand Up @@ -94,6 +93,33 @@ def _get_secondary_auditors(dbkey, year):
return sort_by_field(results, "ID")


def xform_cpafirmname(secondary_auditors):
"""NOTE: We track all secondary_auditors data in change_records.
Save change_records in InspectionRecord only if at least one blank CPAFIRMNAME is found.
We do this so that we can match changedrecord to record in dissemination table in a one on one fashion.
"""

change_records = []
is_empty_cpafirmname_found = False
for secondary_auditor in secondary_auditors:
cpafirmname = string_to_string(secondary_auditor.CPAFIRMNAME)
if cpafirmname == "":
is_empty_cpafirmname_found = True
cpafirmname = settings.GSA_MIGRATION
track_transformations(
"CPAFIRMNAME",
secondary_auditor.CPAFIRMNAME,
"auditor_name",
cpafirmname,
["xform_cpafirmname"],
change_records,
)
secondary_auditor.CPAFIRMNAME = cpafirmname

if change_records and is_empty_cpafirmname_found:
InspectionRecord.append_secondary_auditor_changes(change_records)


def generate_secondary_auditors(audit_header, outfile):
"""
Generates secondary auditor workbook for a given audit header.
Expand All @@ -111,6 +137,7 @@ def generate_secondary_auditors(audit_header, outfile):
audit_header.DBKEY, audit_header.AUDITYEAR
)
xform_address_state(secondary_auditors)
xform_cpafirmname(secondary_auditors)
map_simple_columns(wb, mappings, secondary_auditors)
wb.save(outfile)

Expand Down