Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Display customers with open orders (fixes mirumee/saleor/#217)
Marcin Gębala50b280cbd181
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.pyindex 4f1bc955f9..81d4be2991 100644--- a/saleor/dashboard/customer/views.py+++ b/saleor/dashboard/customer/views.py@@ -11,9 +11,11 @@ class CustomerList(StaffMemberOnlyMixin, ListView):def get_queryset(self):qs = super(CustomerList, self).get_queryset()- qs = qs.prefetch_related('orders').annotate(- num_orders=Count('orders'), last_order=Max('orders'))-+ open_order = ['new', 'payment-pending', 'fully-paid']+ qs = qs.prefetch_related('orders').filter(+ orders__status__in=open_order)+ qs = qs.annotate(num_orders=Count('orders', distinct=True),+ last_order=Max('orders', distinct=True))return qs@@ -26,5 +28,4 @@ class CustomerDetails(StaffMemberOnlyMixin, DetailView):qs = super(CustomerDetails, self).get_queryset()qs = qs.prefetch_related('orders', 'addresses').select_related('default_billing_address')-return qsdiff --git a/saleor/dashboard/templates/dashboard/customer/list.html b/saleor/dashboard/templates/dashboard/customer/list.htmlindex 5ba449087b..7a25cbb03c 100644--- a/saleor/dashboard/templates/dashboard/customer/list.html+++ b/saleor/dashboard/templates/dashboard/customer/list.html@@ -10,39 +10,45 @@<div class="row"><div class="col-lg-12"><h1 class="page-header">{% trans "Customers" %}</h1>-- <table class="table">- <thead>- <th>{% trans "Email" %}</th>- <th>{% trans "Location" %}</th>- <th>{% trans "Number of orders" %}</th>- <th>{% trans "Last order" %}</th>- </thead>- <tbody>- {% for customer in object_list %}- <tr>- {% with customer.default_billing_address as default_address %}- <td>- <a href="{% url "dashboard:customer-details" pk=customer.pk %}">{{ customer.email }}</a>- </td>- <td>- {{ default_address.address.city }}, {{ default_address.address.get_country_display }}- </td>- {% endwith %}- <td>- {{ customer.num_orders }}- </td>- <td>- {% if customer.last_order %}- <a href="{% url 'dashboard:order-details' pk=customer.last_order %}">{{ customer.last_order }}</a>- {% else %}- -- {% endif %}- </td>- </tr>- {% endfor %}- </tbody>- </table>+ <div class="panel panel-default">+ <div class="panel-heading">+ <span class="panel-title">Customers with open orders</span>+ </div>+ <div class="panel-body">+ <table class="table">+ <thead>+ <th>{% trans "Email" %}</th>+ <th>{% trans "Location" %}</th>+ <th>{% trans "Number of orders" %}</th>+ <th>{% trans "Last order" %}</th>+ </thead>+ <tbody>+ {% for customer in object_list %}+ <tr>+ {% with customer.default_billing_address as default_address %}+ <td>+ <a href="{% url "dashboard:customer-details" pk=customer.pk %}">{{ customer.email }}</a>+ </td>+ <td>+ {{ default_address.address.city }}, {{ default_address.address.get_country_display }}+ </td>+ {% endwith %}+ <td>+ {{ customer.num_orders }}+ </td>+ <td>+ {% if customer.last_order %}+ <a href="{% url 'dashboard:order-details' pk=customer.last_order %}">{{ customer.last_order }}</a>+ {% else %}+ -+ {% endif %}+ </td>+ </tr>+ {% endfor %}+ </tbody>+ </table>+ </div>+ </div></div></div>{% endblock %}