diff --git a/src/registrar/management/commands/populate_organization_type.py b/src/registrar/management/commands/populate_organization_type.py index 4f79008db..1610c1f9b 100644 --- a/src/registrar/management/commands/populate_organization_type.py +++ b/src/registrar/management/commands/populate_organization_type.py @@ -1,12 +1,10 @@ import argparse import logging import os -from registrar.signals import create_or_update_organization_type from typing import List from django.core.management import BaseCommand from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper, ScriptDataHelper -from registrar.models import DomainInformation, DomainRequest, Domain -from django.db import transaction +from registrar.models import DomainInformation, DomainRequest logger = logging.getLogger(__name__) @@ -95,12 +93,8 @@ class Command(BaseCommand): if request.generic_org_type is not None: domain_name = request.requested_domain.name request.is_election_board = domain_name in self.domains_with_election_offices_set - if not new_request: - self.request_skipped.append(request) - logger.warning(f"Skipped updating {request}. No changes to be made.") - else: - request = new_request - self.request_to_update.append(request) + request.sync_organization_type() + self.request_to_update.append(request) if debug: logger.info(f"Updating {request} => {request.organization_type}") @@ -130,6 +124,7 @@ class Command(BaseCommand): if info.generic_org_type is not None: domain_name = info.domain.name info.is_election_board = domain_name in self.domains_with_election_offices_set + info = info.sync_organization_type() self.di_to_update.append(info) if debug: logger.info(f"Updating {info} => {info.organization_type}") diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index 2149f429a..b54209750 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -49,6 +49,7 @@ class ScriptDataHelper: Usage: bulk_update_fields(Domain, page.object_list, ["first_ready"]) """ + logger.info(f"{TerminalColors.YELLOW} Bulk updating fields... {TerminalColors.ENDC}") # Create a Paginator object. Bulk_update on the full dataset # is too memory intensive for our current app config, so we can chunk this data instead. paginator = Paginator(update_list, batch_size) diff --git a/src/registrar/models/domain_information.py b/src/registrar/models/domain_information.py index 2ed27504c..6bdc6c00d 100644 --- a/src/registrar/models/domain_information.py +++ b/src/registrar/models/domain_information.py @@ -236,8 +236,11 @@ class DomainInformation(TimeStampedModel): except Exception: return "" - def save(self, *args, **kwargs): - """Save override for custom properties""" + def sync_organization_type(self): + """ + Updates the organization_type (without saving) to match + the is_election_board and generic_organization_type fields. + """ # Define mappings between generic org and election org. # These have to be defined here, as you'd get a cyclical import error @@ -262,6 +265,12 @@ class DomainInformation(TimeStampedModel): # Actually updates the organization_type field org_type_helper.create_or_update_organization_type() + + return self + + def save(self, *args, **kwargs): + """Save override for custom properties""" + self.sync_organization_type() super().save(*args, **kwargs) @classmethod diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index bd529f7e6..1b8a519a0 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -666,9 +666,11 @@ class DomainRequest(TimeStampedModel): help_text="Notes about this request", ) - def save(self, *args, **kwargs): - """Save override for custom properties""" - + def sync_organization_type(self): + """ + Updates the organization_type (without saving) to match + the is_election_board and generic_organization_type fields. + """ # Define mappings between generic org and election org. # These have to be defined here, as you'd get a cyclical import error # otherwise. @@ -692,6 +694,10 @@ class DomainRequest(TimeStampedModel): # Actually updates the organization_type field org_type_helper.create_or_update_organization_type() + + def save(self, *args, **kwargs): + """Save override for custom properties""" + self.sync_organization_type() super().save(*args, **kwargs) def __str__(self):