-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TODO move and DOING clone command
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
47 changes: 47 additions & 0 deletions
47
apps/track/management/commands/process_not_done_time_entries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters