From 2ef537fff6b249a263f12da32b738a4bfc56adb4 Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Thu, 15 Jan 2026 12:54:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=BD=D0=B8=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B2=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B5=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Убрана фильтрация системного клиента из результатов поиска (api_search_customers) - Добавлен флаг is_system_customer в результаты API поиска - Создан новый API endpoint api_get_system_customer для быстрого получения системного клиента - Добавлена кнопка 'Аноним' для быстрого выбора системного клиента - Системный клиент выделяется жёлтым цветом и иконкой инкогнито в выпадающем списке - Улучшена компактность результатов поиска (уменьшен шрифт до 13px) - Изменены пропорции полей: клиент 9 колонок, статус 3 колонки (было 6:6) Co-Authored-By: Claude Opus 4.5 --- myproject/customers/urls.py | 1 + myproject/customers/views.py | 38 +++- .../static/orders/js/customer_select2.js | 8 + .../orders/templates/orders/order_form.html | 206 +++++++++++++++--- 4 files changed, 218 insertions(+), 35 deletions(-) diff --git a/myproject/customers/urls.py b/myproject/customers/urls.py index df260af..1ea67ba 100644 --- a/myproject/customers/urls.py +++ b/myproject/customers/urls.py @@ -21,5 +21,6 @@ urlpatterns = [ # AJAX API endpoints path('api/search/', views.api_search_customers, name='api-search-customers'), path('api/create/', views.api_create_customer, name='api-create-customer'), + path('api/system/', views.api_get_system_customer, name='api-get-system-customer'), path('/api/update/', views.api_update_customer, name='api-update-customer'), ] \ No newline at end of file diff --git a/myproject/customers/views.py b/myproject/customers/views.py index c9c2ad0..f7d1eb0 100644 --- a/myproject/customers/views.py +++ b/myproject/customers/views.py @@ -376,6 +376,39 @@ def build_customer_search_query(query, strategy, search_value): return Q(name__icontains=query) +@require_http_methods(["GET"]) +def api_get_system_customer(request): + """ + AJAX endpoint для получения системного (анонимного) клиента. + + Возвращает JSON с данными системного клиента: + { + "success": true, + "customer": { + "id": 1, + "text": "АНОНИМНЫЙ ПОКУПАТЕЛЬ (POS)", + "name": "АНОНИМНЫЙ ПОКУПАТЕЛЬ (POS)", + "phone": "", + "email": "system@pos.customer", + "is_system_customer": true + } + } + """ + system_customer, _ = Customer.get_or_create_system_customer() + + return JsonResponse({ + 'success': True, + 'customer': { + 'id': system_customer.pk, + 'text': system_customer.name, + 'name': system_customer.name, + 'phone': str(system_customer.phone) if system_customer.phone else '', + 'email': system_customer.email, + 'is_system_customer': True, + } + }) + + @require_http_methods(["GET"]) def api_search_customers(request): """ @@ -456,8 +489,8 @@ def api_search_customers(request): if channel_matches: q_objects |= Q(pk__in=channel_matches) - # Исключаем системного клиента из результатов поиска - customers = Customer.objects.filter(q_objects).filter(is_system_customer=False).distinct().order_by('name')[:20] + # Включаем всех клиентов, включая системного (для возможности выбора в заказах) + customers = Customer.objects.filter(q_objects).distinct().order_by('name')[:20] results = [] @@ -475,6 +508,7 @@ def api_search_customers(request): 'phone': phone_display, 'email': customer.email, 'wallet_balance': float(customer.wallet_balance), + 'is_system_customer': customer.is_system_customer, }) # Если ничего не найдено, предлагаем создать нового клиента diff --git a/myproject/orders/static/orders/js/customer_select2.js b/myproject/orders/static/orders/js/customer_select2.js index a25bdd5..aea438b 100644 --- a/myproject/orders/static/orders/js/customer_select2.js +++ b/myproject/orders/static/orders/js/customer_select2.js @@ -39,6 +39,14 @@ ''; } + // Системный (анонимный) клиент - выделяем стилем + if (option.is_system_customer) { + return '
' + + ' ' + option.name + '' + + '
Системный клиент для анонимных покупок' + + '
'; + } + if (!option.id) { return option.text; } diff --git a/myproject/orders/templates/orders/order_form.html b/myproject/orders/templates/orders/order_form.html index a6c7ddc..f9dbdeb 100644 --- a/myproject/orders/templates/orders/order_form.html +++ b/myproject/orders/templates/orders/order_form.html @@ -45,6 +45,22 @@ font-size: 1.1em; } + /* Стили для системного клиента */ + .system-customer-option { + background-color: #fff3cd; + padding: 8px 12px; + border-radius: 4px; + border-left: 3px solid #ffc107; + } + + .system-customer-option:hover { + background-color: #ffe69c; + } + + .system-customer-option i { + margin-right: 5px; + } + /* Select2 dropdown styling */ .select2-results__option.customer-option-item { padding: 8px 8px; @@ -55,6 +71,50 @@ border-bottom: none; } + /* Компактные стили для результатов поиска клиентов */ + .customer-option { + padding: 4px 0 !important; + font-size: 13px; + line-height: 1.3; + } + + .customer-option small { + font-size: 11px; + line-height: 1.2; + } + + .customer-create-option { + padding: 6px 10px !important; + font-size: 13px; + } + + .system-customer-option { + padding: 6px 10px !important; + font-size: 13px; + line-height: 1.3; + } + + .system-customer-option small { + font-size: 11px; + } + + /* Input group с Select2 и кнопкой системного клиента */ + .customer-select-wrapper { + display: flex; + flex-wrap: nowrap; + gap: 0; + } + + .customer-select-wrapper .select2-container { + flex: 1; + min-width: 0; + } + + .customer-select-wrapper .btn { + flex-shrink: 0; + border-radius: 0 4px 4px 0; + } + /* ИСПРАВЛЕНИЕ: Убедимся что Select2 dropdown видим и поверх всех элементов */ .select2-container--open { z-index: 9999 !important; @@ -85,10 +145,11 @@ .select2-results { max-height: 400px; overflow-y: auto; + font-size: 13px; } .select2-results__option { - padding: 8px 8px; + padding: 6px 8px; color: #212529; } @@ -139,48 +200,54 @@
-
+
- {% if preselected_customer %} - - {% else %} - + - {% endif %} - - {% endif %} + + {% else %} + + {% endif %} + +
{% if form.customer.errors %}
{{ form.customer.errors }}
{% endif %}
-
+