Skip to content

Commit

Permalink
Add TODO move and DOING clone command
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Aug 6, 2024
1 parent 3663995 commit 10cf7d8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Empty file.
Empty file.
47 changes: 47 additions & 0 deletions apps/track/management/commands/process_not_done_time_entries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import datetime
from django.core.management import BaseCommand
from django.utils import timezone

from apps.track.models import TimeEntry


# TODO: Add test cases
class Command(BaseCommand):
help = "Move past TODO and clone past DOING to today"

def move_todo_entries(self, today: datetime.date):
qs = TimeEntry.objects.filter(status=TimeEntry.Status.TODO, date__lt=today)
resp = qs.update(date=today)
self.stdout.write(
self.style.SUCCESS(f'{resp} TODO moved')
)

def clone_doing_entries(self, today: datetime.date):
# Only look for yesterday
qs = TimeEntry.objects.filter(
status=TimeEntry.Status.DOING,
date=today - datetime.timedelta(days=1),
)
cloned_count = 0
for time_entry in qs:
existing_qs = TimeEntry.objects.filter(
status=TimeEntry.Status.TODO,
date=today,
# Fields to check similarity
type=time_entry.type,
description=time_entry.description,
)
if existing_qs.exists():
continue
time_entry.pk = None # Create a new copy
time_entry.status = TimeEntry.Status.TODO # Use todo Status
time_entry.date = today
time_entry.save()
self.stdout.write(
self.style.SUCCESS(f'{cloned_count} DOING cloned')
)

def handle(self, **_):
today = timezone.now().date()
self.move_todo_entries(today)
self.clone_doing_entries(today)
1 change: 1 addition & 0 deletions apps/user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class UserAdmin(DjangoUserAdmin):
"first_name",
"last_name",
"department",
"display_picture",
)
},
),
Expand Down

0 comments on commit 10cf7d8

Please sign in to comment.