From bb79c9de965fc5ae6ea5ef51053e7776e6f5626a Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Fri, 19 May 2023 12:36:12 +0530 Subject: [PATCH] chore: start date for issues (#1075) --- apiserver/back_migration.py | 16 +++++++++++++++- apiserver/plane/db/models/issue.py | 20 ++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/apiserver/back_migration.py b/apiserver/back_migration.py index 0f272755f..c04ee7771 100644 --- a/apiserver/back_migration.py +++ b/apiserver/back_migration.py @@ -204,7 +204,21 @@ def update_integration_verified(): Integration.objects.bulk_update( updated_integrations, ["verified"], batch_size=10 ) - print("Sucess") + print("Success") + except Exception as e: + print(e) + print("Failed") + + +def update_start_date(): + try: + issues = Issue.objects.filter(state__group__in=["started", "completed"]) + updated_issues = [] + for issue in issues: + issue.start_date = issue.created_at.date() + updated_issues.append(issue) + Issue.objects.bulk_update(updated_issues, ["start_date"], batch_size=500) + print("Success") except Exception as e: print(e) print("Failed") diff --git a/apiserver/plane/db/models/issue.py b/apiserver/plane/db/models/issue.py index fed946a61..6e264566d 100644 --- a/apiserver/plane/db/models/issue.py +++ b/apiserver/plane/db/models/issue.py @@ -85,8 +85,13 @@ class Issue(ProjectBaseModel): ).first() # if there is no default state assign any random state if default_state is None: - self.state = State.objects.filter(project=self.project).first() + random_state = State.objects.filter(project=self.project).first() + self.state = random_state + if random_state.group == "started": + self.start_date = timezone.now().date() else: + if default_state.group == "started": + self.start_date = timezone.now().date() self.state = default_state except ImportError: pass @@ -94,18 +99,15 @@ class Issue(ProjectBaseModel): try: from plane.db.models import State, PageBlock - # Get the completed states of the project - completed_states = State.objects.filter( - group="completed", project=self.project - ).values_list("pk", flat=True) # Check if the current issue state and completed state id are same - if self.state.id in completed_states: + if self.state.group == "completed": self.completed_at = timezone.now() # check if there are any page blocks PageBlock.objects.filter(issue_id=self.id).filter().update( completed_at=timezone.now() ) - + elif self.state.group == "started": + self.start_date = timezone.now().date() else: PageBlock.objects.filter(issue_id=self.id).filter().update( completed_at=None @@ -116,7 +118,6 @@ class Issue(ProjectBaseModel): pass if self._state.adding: # Get the maximum display_id value from the database - last_id = IssueSequence.objects.filter(project=self.project).aggregate( largest=models.Max("sequence") )["largest"] @@ -131,6 +132,9 @@ class Issue(ProjectBaseModel): if largest_sort_order is not None: self.sort_order = largest_sort_order + 10000 + # If adding it to started state + if self.state.group == "started": + self.start_date = timezone.now().date() # Strip the html tags using html parser self.description_stripped = ( None