diff --git a/src/registrar/management/commands/populate_domain_request_dates.py b/src/registrar/management/commands/populate_domain_request_dates.py new file mode 100644 index 000000000..7ea898c4c --- /dev/null +++ b/src/registrar/management/commands/populate_domain_request_dates.py @@ -0,0 +1,21 @@ +import logging +from django.core.management import BaseCommand +from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors +from registrar.models import DomainRequest + +logger = logging.getLogger(__name__) + + +class Command(BaseCommand, PopulateScriptTemplate): + help = "Loops through each valid domain request object and populates the last_status_update and first_submitted_date" + + def handle(self, **kwargs): + """Loops through each valid DomainRequest object and populates its last_status_update and first_submitted_date values""" + self.mass_update_records(DomainRequest, ["last_status_update", "last_submitted_date"]) + + def update_record(self, record: DomainRequest): + """Defines how we update the first_submitted_date and last_status_update fields""" + record.set_dates() + logger.info( + f"{TerminalColors.OKCYAN}Updating {record} => first submitted date: " f"{record.first_submitted_date}{TerminalColors.OKCYAN}, last status update:" f"{record.last_status_update}{TerminalColors.OKCYAN}" + ) diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index 363de213b..d2c90243c 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -563,15 +563,32 @@ class DomainRequest(TimeStampedModel): help_text="Acknowledged .gov acceptable use policy", ) - # submission date records when domain request is submitted - submission_date = models.DateField( + # initial submission date records when domain request was first submitted + first_submitted_date = models.DateField( null=True, blank=True, default=None, verbose_name="submitted at", - help_text="Date submitted", + help_text="Date initially submitted", ) + # last submission date records when domain request was last submitted + last_submitted_date = models.DateField( + null=True, + blank=True, + default=None, + verbose_name="submitted at", + help_text="Date last submitted", + ) + + # last status update records when domain request status was last updated by an admin or analyst + last_status_update = models.DateField( + null=True, + blank=True, + default=None, + verbose_name="last updated at", + help_text="Date of last status updated", + ) notes = models.TextField( null=True, blank=True, @@ -621,6 +638,9 @@ class DomainRequest(TimeStampedModel): self.sync_organization_type() self.sync_yes_no_form_fields() + if self._cached_status != self.status: + self.last_status_update = timezone.now().date() + super().save(*args, **kwargs) # Handle the action needed email. @@ -796,9 +816,12 @@ class DomainRequest(TimeStampedModel): DraftDomain = apps.get_model("registrar.DraftDomain") if not DraftDomain.string_could_be_domain(self.requested_domain.name): raise ValueError("Requested domain is not a valid domain name.") + + if not self.first_submitted_date: + self.first_submitted_date = timezone.now().date() - # Update submission_date to today - self.submission_date = timezone.now().date() + # Update last_submission_date to today + self.last_submitted_date = timezone.now().date() self.save() # Limit email notifications to transitions from Started and Withdrawn