Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add first and last name in order search and filter
fowczareke9e1587c22f4
diff --git a/saleor/dashboard/order/filters.py b/saleor/dashboard/order/filters.pyindex 1d394b477f..3f970fb526 100644--- a/saleor/dashboard/order/filters.py+++ b/saleor/dashboard/order/filters.py@@ -64,6 +64,8 @@ class OrderFilter(SortedFilterSet):def filter_by_order_customer(self, queryset, name, value):return queryset.filter(Q(user__email__icontains=value) |+ Q(user__first_name__icontains=value) |+ Q(user__last_name__icontains=value) |Q(user__default_billing_address__first_name__icontains=value) |Q(user__default_billing_address__last_name__icontains=value))diff --git a/saleor/search/backends/postgresql_dashboard.py b/saleor/search/backends/postgresql_dashboard.pyindex 265d40fac8..4182b009de 100644--- a/saleor/search/backends/postgresql_dashboard.py+++ b/saleor/search/backends/postgresql_dashboard.py@@ -28,6 +28,8 @@ def search_orders(phrase):passsv = (+ SearchVector('user__first_name', weight='B') ++ SearchVector('user__last_name', weight='B') +SearchVector('user__default_shipping_address__first_name', weight='B') +SearchVector('user__default_shipping_address__last_name', weight='B') +diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex 6744485357..85e341c87d 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -199,6 +199,9 @@</span>{% if order.user %}<a href="{% url 'dashboard:customer-details' pk=order.user.pk %}">{{ order.user }}</a>+ {% if order.user.get_full_name != order.user.email %}+ <p>{{ order.user.get_full_name|truncatechars:80 }}</p>+ {% endif %}{% if order.user.note %}<p>{{ order.user.note|truncatechars:80 }}</p>{% endif %}diff --git a/tests/test_postgresql_search.py b/tests/test_postgresql_search.pyindex 05ff1ed56b..055a8aa6a9 100644--- a/tests/test_postgresql_search.py+++ b/tests/test_postgresql_search.py@@ -130,6 +130,17 @@ def orders_with_addresses():return orders+def orders_with_user_names():+ orders = []+ for pk, first_name, last_name, email in ORDERS:+ user = User.objects.create(+ email=email, first_name=first_name, last_name=last_name)+ order = Order.objects.create(user=user, pk=pk)+ orders.append(order)+ return orders++@pytest.mark.integration@pytest.mark.django_db(transaction=True)def test_find_order_by_id_with_no_result(admin_client, orders_with_addresses):@@ -169,6 +180,17 @@ def test_find_order_with_user_name(admin_client, orders_with_addresses, phrase,assert orders_with_addresses[order_num] in orders[email protected]_db(transaction=True)[email protected]('phrase,order_num', [('knop', 0), ('ZIEMniak', 1),+ (' john ', 2), ('ANDREAS', 0)])+def test_find_order_with_user_name_without_addres(+ admin_client, orders_with_user_names, phrase, order_num):+ _, orders, _ = search_dashboard(admin_client, phrase)+ assert 1 == len(orders)+ assert orders_with_user_names[order_num] in orders++ORDER_PHRASE_WITH_RESULT = 'Andreas'ORDER_RESULTS_PERMISSION = 'order.manage_orders'@@ -203,6 +225,16 @@ def users_with_addresses():return users+def users_with_names():+ users = []+ for firstname, lastname, email in USERS:+ user = User.objects.create(+ email=email, first_name=firstname, last_name=lastname)+ users.append(user)+ return users++@pytest.mark.integration@pytest.mark.django_db(transaction=True)@pytest.mark.parametrize('phrase,user_num', [('[email protected]', 0),@@ -225,6 +257,17 @@ def test_find_user_by_name(admin_client, users_with_addresses, phrase,assert users_with_addresses[user_num] in users[email protected]_db(transaction=True)[email protected]('phrase,user_num', [('Andreas Knop', 0),+ (' Euzebiusz ', 1), ('DOE', 2)])+def test_find_user_by_name_without_address(admin_client, users_with_names,+ phrase, user_num):+ _, _, users = search_dashboard(admin_client, phrase)+ assert 1 == len(users)+ assert users_with_names[user_num] in users++USER_PHRASE_WITH_RESULT = '[email protected]'USER_RESULTS_PERMISSION = 'account.manage_users'