feat: добавлена интеграция синхронизации с Recommerce

This commit is contained in:
2026-01-12 21:45:31 +03:00
parent a5ab216934
commit 707b45b16d
13 changed files with 475 additions and 104 deletions

View File

@@ -5,6 +5,7 @@ from django.views.decorators.http import require_POST
from user_roles.mixins import OwnerRequiredMixin
from .models import RecommerceIntegration, WooCommerceIntegration
from integrations.recommerce.tasks import sync_products_batch_task
# Реестр доступных интеграций
@@ -148,6 +149,44 @@ def get_integration_service(integration_id: str, instance):
return None
class RecommerceBatchSyncView(TemplateView):
"""
API View для запуска массовой синхронизации с Recommerce.
POST /integrations/recommerce/sync/
"""
def dispatch(self, request, *args, **kwargs):
# Временное логирование для отладки
from user_roles.services import RoleService
import logging
logger = logging.getLogger(__name__)
logger.info(f"User: {request.user}, Authenticated: {request.user.is_authenticated}")
user_role = RoleService.get_user_role(request.user)
logger.info(f"User role: {user_role}")
return super().dispatch(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
try:
data = json.loads(request.body)
product_ids = data.get('product_ids', [])
options = data.get('options', {})
if not product_ids:
return JsonResponse({'error': 'No products selected'}, status=400)
# Запуск Celery задачи с передачей schema_name
from django_tenants.utils import get_tenant_model
Tenant = get_tenant_model()
schema_name = request.tenant.schema_name
task = sync_products_batch_task.delay(product_ids, options, schema_name)
return JsonResponse({
'success': True,
'task_id': task.id,
'message': f'Запущена синхронизация {len(product_ids)} товаров'
})
except Exception as e:
return JsonResponse({'error': str(e)}, status=500)
@require_POST
def save_integration_settings(request, integration_id: str):
"""