Proper order filtering for customer view
This commit is contained in:
parent
c60433c8d2
commit
332840aa3b
@ -165,6 +165,11 @@ class OrderManager(models.Manager):
|
|||||||
def with_lines(self):
|
def with_lines(self):
|
||||||
return self.select_related('lines')
|
return self.select_related('lines')
|
||||||
|
|
||||||
|
def without_drafts(self):
|
||||||
|
return self.exclude(
|
||||||
|
status=OrderStatus.DRAFT
|
||||||
|
)
|
||||||
|
|
||||||
def with_fulfillment(self):
|
def with_fulfillment(self):
|
||||||
return self.annotate(
|
return self.annotate(
|
||||||
total_quantity_fulfilled=models.Sum('lines__quantity_fulfilled'),
|
total_quantity_fulfilled=models.Sum('lines__quantity_fulfilled'),
|
||||||
|
|||||||
@ -577,13 +577,20 @@ article > header {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
align-content: center;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.article__header--with-action h1 {
|
.article__header--with-action h1 {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.article__header--with-action {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
article + article {
|
article + article {
|
||||||
margin-top: 8rem;
|
margin-top: 8rem;
|
||||||
}
|
}
|
||||||
@ -897,6 +904,13 @@ article + article {
|
|||||||
gap: 4rem;
|
gap: 4rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.customer__detail-section {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,6 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{% with order_list=customer.orders.all %}
|
|
||||||
<section>
|
<section>
|
||||||
<h3>Your orders</h3>
|
<h3>Your orders</h3>
|
||||||
<table>
|
<table>
|
||||||
@ -73,7 +72,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>#{{order.pk}}</td>
|
<td>#{{order.pk}}</td>
|
||||||
<td>{{order.created_at|date:"M j, Y"}}</td>
|
<td>{{order.created_at|date:"M j, Y"}}</td>
|
||||||
<td>${{order.total_net_amount}}</td>
|
<td>${{order.get_total_price_after_discount}}</td>
|
||||||
<td><a href="{% url 'storefront:order-detail' customer.pk order.pk %}">See details →</a></td>
|
<td><a href="{% url 'storefront:order-detail' customer.pk order.pk %}">See details →</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
@ -82,6 +81,5 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</section>
|
</section>
|
||||||
{% endwith %}
|
|
||||||
</article>
|
</article>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|||||||
@ -56,6 +56,10 @@
|
|||||||
<td>{{order.coupon.discount_value}} {{order.coupon.get_discount_value_type_display}}</td>
|
<td>{{order.coupon.discount_value}} {{order.coupon.get_discount_value_type_display}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<tr>
|
||||||
|
<td>Shipping</td>
|
||||||
|
<td>${{order.shipping_total}}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Total</th>
|
<th>Total</th>
|
||||||
<td><strong>${{order.get_total_price_after_discount}}</strong></td>
|
<td><strong>${{order.get_total_price_after_discount}}</strong></td>
|
||||||
|
|||||||
@ -337,6 +337,13 @@ class CustomerDetailView(UserPassesTestMixin, LoginRequiredMixin, DetailView):
|
|||||||
permission_denied_message = 'Not authorized.'
|
permission_denied_message = 'Not authorized.'
|
||||||
raise_exception = True
|
raise_exception = True
|
||||||
|
|
||||||
|
def get_context_data(self, *args, **kwargs):
|
||||||
|
context = super().get_context_data(*args, **kwargs)
|
||||||
|
context['order_list'] = Order.objects.without_drafts().filter(
|
||||||
|
customer=self.object
|
||||||
|
).prefetch_related('lines')
|
||||||
|
return context
|
||||||
|
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
return self.request.user.pk == self.get_object().pk
|
return self.request.user.pk == self.get_object().pk
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user