refactor: remove unused cleanup_draft_orders management command
The cleanup_draft_orders command was no longer needed in the project. Also updated test output file with latest test results. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,95 +0,0 @@
|
||||
"""
|
||||
Management :><0=40 4;O >G8AB:8 AB0@KE G5@=>28:>2 70:07>2.
|
||||
|
||||
#40;O5B G5@=>28:8 70:07>2, :>B>@K5 =5 >1=>2;O;8AL 1>;55 C:070==>3> :>;8G5AB20 4=59.
|
||||
"0:65 C40;O5B A2O70==K5 2@5<5==K5 :><?;5:BK.
|
||||
|
||||
A?>;L7>20=85:
|
||||
python manage.py cleanup_draft_orders --days=30
|
||||
python manage.py cleanup_draft_orders --days=7 --dry-run
|
||||
"""
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from orders.services import DraftOrderService
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '#40;O5B AB0@K5 G5@=>28:8 70:07>2 8 A2O70==K5 2@5<5==K5 :><?;5:BK'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--days',
|
||||
type=int,
|
||||
default=30,
|
||||
help='>;8G5AB2> 4=59, ?>A;5 :>B>@KE G5@=>28: AG8B05BAO AB0@K< (?> C<>;G0=8N: 30)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--dry-run',
|
||||
action='store_true',
|
||||
help='>:070BL :>;8G5AB2> G5@=>28:>2 4;O C40;5=8O 157 D0:B8G5A:>3> C40;5=8O'
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
days = options['days']
|
||||
dry_run = options['dry_run']
|
||||
|
||||
if days < 1:
|
||||
raise CommandError('>;8G5AB2> 4=59 4>;6=> 1KBL 1>;LH5 0')
|
||||
|
||||
self.stdout.write(
|
||||
self.style.WARNING(
|
||||
f'>8A: G5@=>28:>2 AB0@H5 {days} 4=59...'
|
||||
)
|
||||
)
|
||||
|
||||
if dry_run:
|
||||
# @568<5 dry-run B>;L:> ?>4AG8BK205<
|
||||
from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
from orders.models import Order
|
||||
|
||||
cutoff_date = timezone.now() - timedelta(days=days)
|
||||
old_drafts = Order.objects.filter(
|
||||
status__code='draft',
|
||||
last_autosave_at__lt=cutoff_date
|
||||
)
|
||||
count = old_drafts.count()
|
||||
|
||||
if count == 0:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f'5B G5@=>28:>2 AB0@H5 {days} 4=59'
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.WARNING(
|
||||
f'0945=> {count} G5@=>28:>2 4;O C40;5=8O:'
|
||||
)
|
||||
)
|
||||
for draft in old_drafts:
|
||||
last_save = draft.last_autosave_at.strftime('%d.%m.%Y %H:%M') if draft.last_autosave_at else '=8:>340'
|
||||
self.stdout.write(
|
||||
f' - 0:07 #{draft.order_number} (?>A;54=55 A>E@0=5=85: {last_save})'
|
||||
)
|
||||
self.stdout.write(
|
||||
self.style.WARNING(
|
||||
f'\n0?CAB8B5 157 --dry-run 4;O D0:B8G5A:>3> C40;5=8O'
|
||||
)
|
||||
)
|
||||
else:
|
||||
# $0:B8G5A:>5 C40;5=85
|
||||
count = DraftOrderService.delete_old_drafts(days=days)
|
||||
|
||||
if count == 0:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f'5B G5@=>28:>2 AB0@H5 {days} 4=59'
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f'#A?5H=> C40;5=> {count} G5@=>28:>2 8 A2O70==KE 2@5<5==KE :><?;5:B>2'
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user