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'
|
||||
)
|
||||
)
|
||||
@@ -268,92 +268,29 @@ ERROR: test_01_draft_to_completed_to_cancelled_to_completed (inventory.tests.tes
|
||||
╩╨╚╥╚╫┼╤╩╚╔ ╥┼╤╥ #1: ╠эюцхёЄтхээ√х яхЁхїюф√ ьхцфє ёЄрЄєёрьш
|
||||
----------------------------------------------------------------------
|
||||
Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(7)
|
||||
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 80, in setUp
|
||||
self._create_system_entities()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 101, in _create_system_entities
|
||||
self.status_draft = OrderStatus.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='draft',
|
||||
^^^^^^^^^^^^^
|
||||
...<5 lines>...
|
||||
order=0
|
||||
^^^^^^^
|
||||
)
|
||||
^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\manager.py", line 87, in manager_method
|
||||
return getattr(self.get_queryset(), name)(*args, **kwargs)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\query.py", line 679, in create
|
||||
obj.save(force_insert=True, using=self.db)
|
||||
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\base.py", line 822, in save
|
||||
self.save_base(
|
||||
~~~~~~~~~~~~~~^
|
||||
using=using,
|
||||
^^^^^^^^^^^^
|
||||
...<2 lines>...
|
||||
update_fields=update_fields,
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
)
|
||||
^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\base.py", line 909, in save_base
|
||||
updated = self._save_table(
|
||||
raw,
|
||||
...<4 lines>...
|
||||
update_fields,
|
||||
)
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\base.py", line 1071, in _save_table
|
||||
results = self._do_insert(
|
||||
cls._base_manager, using, fields, returning_fields, raw
|
||||
)
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\base.py", line 1112, in _do_insert
|
||||
return manager._insert(
|
||||
~~~~~~~~~~~~~~~^
|
||||
[self],
|
||||
^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 83, in setUp
|
||||
self._create_test_data()
|
||||
~~~~~~~~~~~~~~~~~~~~~~^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 184, in _create_test_data
|
||||
self.product = Product.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~^
|
||||
name='╥хёЄют√щ ЄютрЁ',
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
...<3 lines>...
|
||||
raw=raw,
|
||||
^^^^^^^^
|
||||
base_price=Decimal('10.00')
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
)
|
||||
^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\manager.py", line 87, in manager_method
|
||||
return getattr(self.get_queryset(), name)(*args, **kwargs)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\query.py", line 1847, in _insert
|
||||
return query.get_compiler(using=using).execute_sql(returning_fields)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\sql\compiler.py", line 1823, in execute_sql
|
||||
cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 79, in execute
|
||||
return self._execute_with_wrappers(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
sql, params, many=False, executor=self._execute
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\query.py", line 677, in create
|
||||
obj = self.model(**kwargs)
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\base.py", line 567, in __init__
|
||||
raise TypeError(
|
||||
...<2 lines>...
|
||||
)
|
||||
^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 92, in _execute_with_wrappers
|
||||
return executor(sql, params, many, context)
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 100, in _execute
|
||||
with self.db.wrap_database_errors:
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\utils.py", line 91, in __exit__
|
||||
raise dj_exc_value.with_traceback(traceback) from exc_value
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
django.db.utils.DataError: value too long for type character varying(7)
|
||||
|
||||
TypeError: Product() got unexpected keyword arguments: 'category', 'base_price'
|
||||
|
||||
======================================================================
|
||||
ERROR: test_01_draft_to_completed_to_cancelled_to_completed (inventory.tests.test_order_status_transitions.OrderStatusTransitionCriticalTest.test_01_draft_to_completed_to_cancelled_to_completed)
|
||||
@@ -441,7 +378,8 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(7)
|
||||
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "orders_paymentmethod_code_key"
|
||||
DETAIL: Key (code)=(cash) already exists.
|
||||
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
@@ -450,14 +388,14 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 80, in setUp
|
||||
self._create_system_entities()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 101, in _create_system_entities
|
||||
self.status_draft = OrderStatus.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='draft',
|
||||
^^^^^^^^^^^^^
|
||||
...<5 lines>...
|
||||
order=0
|
||||
^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 156, in _create_system_entities
|
||||
self.payment_method = PaymentMethod.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='cash',
|
||||
^^^^^^^^^^^^
|
||||
...<2 lines>...
|
||||
is_active=True
|
||||
^^^^^^^^^^^^^^
|
||||
)
|
||||
^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\manager.py", line 87, in manager_method
|
||||
@@ -522,7 +460,8 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
django.db.utils.DataError: value too long for type character varying(7)
|
||||
django.db.utils.IntegrityError: duplicate key value violates unique constraint "orders_paymentmethod_code_key"
|
||||
DETAIL: Key (code)=(cash) already exists.
|
||||
|
||||
|
||||
======================================================================
|
||||
@@ -611,7 +550,8 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(7)
|
||||
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "orders_paymentmethod_code_key"
|
||||
DETAIL: Key (code)=(cash) already exists.
|
||||
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
@@ -620,14 +560,14 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 80, in setUp
|
||||
self._create_system_entities()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 101, in _create_system_entities
|
||||
self.status_draft = OrderStatus.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='draft',
|
||||
^^^^^^^^^^^^^
|
||||
...<5 lines>...
|
||||
order=0
|
||||
^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 156, in _create_system_entities
|
||||
self.payment_method = PaymentMethod.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='cash',
|
||||
^^^^^^^^^^^^
|
||||
...<2 lines>...
|
||||
is_active=True
|
||||
^^^^^^^^^^^^^^
|
||||
)
|
||||
^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\manager.py", line 87, in manager_method
|
||||
@@ -692,7 +632,8 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
django.db.utils.DataError: value too long for type character varying(7)
|
||||
django.db.utils.IntegrityError: duplicate key value violates unique constraint "orders_paymentmethod_code_key"
|
||||
DETAIL: Key (code)=(cash) already exists.
|
||||
|
||||
|
||||
======================================================================
|
||||
@@ -781,7 +722,8 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(7)
|
||||
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "orders_paymentmethod_code_key"
|
||||
DETAIL: Key (code)=(cash) already exists.
|
||||
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
@@ -790,14 +732,14 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 80, in setUp
|
||||
self._create_system_entities()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 101, in _create_system_entities
|
||||
self.status_draft = OrderStatus.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='draft',
|
||||
^^^^^^^^^^^^^
|
||||
...<5 lines>...
|
||||
order=0
|
||||
^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 156, in _create_system_entities
|
||||
self.payment_method = PaymentMethod.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='cash',
|
||||
^^^^^^^^^^^^
|
||||
...<2 lines>...
|
||||
is_active=True
|
||||
^^^^^^^^^^^^^^
|
||||
)
|
||||
^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\manager.py", line 87, in manager_method
|
||||
@@ -862,7 +804,8 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
django.db.utils.DataError: value too long for type character varying(7)
|
||||
django.db.utils.IntegrityError: duplicate key value violates unique constraint "orders_paymentmethod_code_key"
|
||||
DETAIL: Key (code)=(cash) already exists.
|
||||
|
||||
|
||||
======================================================================
|
||||
@@ -951,7 +894,8 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(7)
|
||||
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "orders_paymentmethod_code_key"
|
||||
DETAIL: Key (code)=(cash) already exists.
|
||||
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
@@ -960,14 +904,14 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 80, in setUp
|
||||
self._create_system_entities()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 101, in _create_system_entities
|
||||
self.status_draft = OrderStatus.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='draft',
|
||||
^^^^^^^^^^^^^
|
||||
...<5 lines>...
|
||||
order=0
|
||||
^^^^^^^
|
||||
File "C:\Users\team_\Desktop\test_qwen\myproject\inventory\tests\test_order_status_transitions.py", line 156, in _create_system_entities
|
||||
self.payment_method = PaymentMethod.objects.create(
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
code='cash',
|
||||
^^^^^^^^^^^^
|
||||
...<2 lines>...
|
||||
is_active=True
|
||||
^^^^^^^^^^^^^^
|
||||
)
|
||||
^
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\models\manager.py", line 87, in manager_method
|
||||
@@ -1032,7 +976,8 @@ Traceback (most recent call last):
|
||||
File "C:\Users\team_\Desktop\test_qwen\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
|
||||
return self.cursor.execute(sql, params)
|
||||
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
|
||||
django.db.utils.DataError: value too long for type character varying(7)
|
||||
django.db.utils.IntegrityError: duplicate key value violates unique constraint "orders_paymentmethod_code_key"
|
||||
DETAIL: Key (code)=(cash) already exists.
|
||||
|
||||
|
||||
======================================================================
|
||||
@@ -1114,7 +1059,7 @@ django.core.management.base.CommandError: Database test_inventory_db couldn't be
|
||||
Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 5 tests in 7.596s
|
||||
Ran 5 tests in 7.828s
|
||||
|
||||
FAILED (errors=10)
|
||||
Destroying test database for alias 'default' ('test_inventory_db')...
|
||||
|
||||
Reference in New Issue
Block a user