feat(orders): add recipient management and enhance order forms
- Introduced Recipient model to manage order recipients separately from customers. - Updated Order model to link to Recipient, replacing recipient_name and recipient_phone fields. - Enhanced OrderForm to include recipient selection modes: customer, history, and new. - Added AJAX endpoint to fetch recipient history for customers. - Updated admin interface to manage recipients and display recipient information in order details. - Refactored address handling to accommodate new recipient logic. - Improved demo order creation to include random recipients.
This commit is contained in:
@@ -17,6 +17,7 @@ from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.core.files.storage import default_storage
|
||||
from django.utils import timezone
|
||||
from tenants.models import RESERVED_SCHEMA_NAMES
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -258,6 +259,19 @@ def cleanup_temp_media_for_schema(schema_name, ttl_hours=None):
|
||||
from django.conf import settings
|
||||
|
||||
try:
|
||||
# Пропускаем зарезервированные схемы (public, admin и т.д.)
|
||||
if schema_name in RESERVED_SCHEMA_NAMES:
|
||||
ttl = int(ttl_hours or getattr(settings, 'TEMP_MEDIA_TTL_HOURS', 24))
|
||||
logger.info(f"[Cleanup:{schema_name}] Skipping reserved schema")
|
||||
return {
|
||||
'status': 'skipped',
|
||||
'schema_name': schema_name,
|
||||
'reason': 'reserved_schema',
|
||||
'deleted': 0,
|
||||
'scanned': 0,
|
||||
'ttl_hours': ttl
|
||||
}
|
||||
|
||||
# Активируем схему тенанта
|
||||
connection.set_schema(schema_name)
|
||||
|
||||
@@ -272,7 +286,15 @@ def cleanup_temp_media_for_schema(schema_name, ttl_hours=None):
|
||||
for rel_dir in temp_dirs:
|
||||
try:
|
||||
# Получаем полный путь с учётом tenant_id
|
||||
full_dir = default_storage.path(rel_dir)
|
||||
try:
|
||||
full_dir = default_storage.path(rel_dir)
|
||||
except RuntimeError as storage_error:
|
||||
# Если не удается определить tenant_id (например, для public схемы)
|
||||
if 'Cannot determine tenant ID' in str(storage_error):
|
||||
logger.warning(f"[Cleanup:{schema_name}] Skipping {rel_dir}: {storage_error}")
|
||||
continue
|
||||
raise # Перебрасываем другие ошибки
|
||||
|
||||
if not os.path.isdir(full_dir):
|
||||
continue
|
||||
|
||||
@@ -331,7 +353,9 @@ def cleanup_temp_media_all(ttl_hours=None):
|
||||
connection.set_schema('public')
|
||||
from tenants.models import Client
|
||||
|
||||
schemas = list(Client.objects.values_list('schema_name', flat=True))
|
||||
# Фильтруем зарезервированные схемы, чтобы не запускать задачи для них
|
||||
schemas = [s for s in Client.objects.values_list('schema_name', flat=True)
|
||||
if s not in RESERVED_SCHEMA_NAMES]
|
||||
ttl = ttl_hours or getattr(settings, 'TEMP_MEDIA_TTL_HOURS', 24)
|
||||
|
||||
logger.info(f"[CleanupAll] Scheduling cleanup for {len(schemas)} tenants (TTL: {ttl}h)")
|
||||
|
||||
Reference in New Issue
Block a user