Remove logic for location information

This commit is contained in:
zandercymatics 2024-08-30 08:40:04 -06:00
parent f2288673a0
commit b3b415b563
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 18 additions and 44 deletions

View file

@ -98,6 +98,7 @@ class Command(BaseCommand):
# Update everything else
for key, value in portfolio_args.items():
setattr(portfolio, key, value)
portfolio.save()
message = f"Modified portfolio '{portfolio}'"
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
@ -126,11 +127,13 @@ class Command(BaseCommand):
new_suborgs = []
for name in org_names - set(existing_suborgs.values_list("name", flat=True)):
if name.lower() == portfolio.organization_name.lower():
# If the suborg name is a portfolio name that currently exists, thats not a suborg - thats the portfolio itself!
# In this case, we can use this as an opportunity to update address information.
self._update_portfolio_location_details(
portfolio, valid_agencies.filter(organization_name=name).first()
# You can use this to populate location information, when this occurs.
# However, this isn't needed for now so we can skip it.
message = (
f"Skipping suborganization create on record '{name}'. "
f"The federal agency name is the same as the portfolio name."
)
TerminalHelper.colorful_logger(logger.warning, TerminalColors.YELLOW, message)
else:
new_suborgs.append(Suborganization(name=name, portfolio=portfolio))
@ -165,29 +168,6 @@ class Command(BaseCommand):
message = f"Updated {len(orgs_to_update)} suborganizations"
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
def _update_portfolio_location_details(self, portfolio: Portfolio, domain_info: DomainInformation):
"""
Update portfolio location details based on DomainInformation.
Copies relevant fields and saves the portfolio.
"""
location_props = [
"address_line1",
"address_line2",
"city",
"state_territory",
"zipcode",
"urbanization",
]
for prop_name in location_props:
# Copy the value from the domain info object to the portfolio object
value = getattr(domain_info, prop_name)
setattr(portfolio, prop_name, value)
portfolio.save()
message = f"Updated location details on portfolio '{portfolio}'"
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message)
def handle_portfolio_requests(self, portfolio: Portfolio, federal_agency: FederalAgency):
"""
Associate portfolio with domain requests for a federal agency.
@ -198,9 +178,7 @@ class Command(BaseCommand):
DomainRequest.DomainRequestStatus.INELIGIBLE,
DomainRequest.DomainRequestStatus.REJECTED,
]
domain_requests = DomainRequest.objects.filter(
federal_agency=federal_agency
).exclude(status__in=invalid_states)
domain_requests = DomainRequest.objects.filter(federal_agency=federal_agency).exclude(status__in=invalid_states)
if not domain_requests.exists():
message = "Portfolios not added to domain requests: no valid records found"
TerminalHelper.colorful_logger(logger.info, TerminalColors.YELLOW, message)

View file

@ -912,7 +912,6 @@ def completed_domain_request( # noqa
action_needed_reason=None,
portfolio=None,
organization_name=None,
city=None,
):
"""A completed domain request."""
if not user:
@ -986,9 +985,6 @@ def completed_domain_request( # noqa
if portfolio:
domain_request_kwargs["portfolio"] = portfolio
if city:
domain_request_kwargs["city"] = city
domain_request, _ = DomainRequest.objects.get_or_create(**domain_request_kwargs)
if has_other_contacts:

View file

@ -1422,13 +1422,15 @@ class TestCreateFederalPortfolio(TestCase):
self.mock_client = MockSESClient()
self.user = User.objects.create(username="testuser")
self.federal_agency = FederalAgency.objects.create(agency="Test Federal Agency")
self.senior_official = SeniorOfficial.objects.create(
first_name="first", last_name="last", email="testuser@igorville.gov", federal_agency=self.federal_agency
)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
self.domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
generic_org_type=DomainRequest.OrganizationChoices.CITY,
federal_agency=self.federal_agency,
user=self.user,
city="WrongCity",
)
self.domain_request.approve()
self.domain_info = DomainInformation.objects.filter(domain_request=self.domain_request).get()
@ -1436,11 +1438,10 @@ class TestCreateFederalPortfolio(TestCase):
self.domain_request_2 = completed_domain_request(
name="sock@igorville.org",
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
generic_org_type=DomainRequest.OrganizationChoices.CITY,
federal_agency=self.federal_agency,
user=self.user,
organization_name="Test Federal Agency",
city="Block",
)
self.domain_request_2.approve()
self.domain_info_2 = DomainInformation.objects.filter(domain_request=self.domain_request_2).get()
@ -1450,6 +1451,7 @@ class TestCreateFederalPortfolio(TestCase):
DomainRequest.objects.all().delete()
Suborganization.objects.all().delete()
Portfolio.objects.all().delete()
SeniorOfficial.objects.all().delete()
FederalAgency.objects.all().delete()
User.objects.all().delete()
@ -1477,11 +1479,8 @@ class TestCreateFederalPortfolio(TestCase):
self.assertEqual(suborganizations.count(), 1)
self.assertEqual(suborganizations.first().name, "Testorg")
# Test other address information
self.assertEqual(portfolio.address_line1, "address 1")
self.assertEqual(portfolio.city, "Block")
self.assertEqual(portfolio.state_territory, "NY")
self.assertEqual(portfolio.zipcode, "10002")
# Test the senior official
self.assertEqual(portfolio.senior_official, self.senior_official)
def test_handle_portfolio_requests(self):
self.run_create_federal_portfolio("Test Federal Agency", parse_requests=True)
@ -1535,6 +1534,7 @@ class TestCreateFederalPortfolio(TestCase):
existing_portfolio.refresh_from_db()
self.assertEqual(existing_portfolio.organization_name, self.federal_agency.agency)
self.assertEqual(existing_portfolio.organization_type, DomainRequest.OrganizationChoices.FEDERAL)
# Notes and creator should be untouched
self.assertEqual(existing_portfolio.notes, "Old notes")
self.assertEqual(existing_portfolio.creator, self.user)