Cancellation of orders. Close #18

This commit is contained in:
Víðir Valberg Guðmundsson 2016-05-31 21:01:48 +02:00
parent 5e8d55d553
commit 9e31be2f11
3 changed files with 8 additions and 4 deletions

View file

@ -67,6 +67,7 @@
{% if not order.open == None %} {% if not order.open == None %}
{% bootstrap_button "Update order" button_type="submit" button_class="btn-primary" name="update_order" %} {% bootstrap_button "Update order" button_type="submit" button_class="btn-primary" name="update_order" %}
{% bootstrap_button "Cancel order" button_type="submit" button_class="btn-danger pull-right" name="cancel_order" %}
{% endif %} {% endif %}
<hr /> <hr />

View file

@ -38,10 +38,6 @@
<td> <td>
{% url 'shop:order_detail' pk=order.pk as order_detail_url %} {% url 'shop:order_detail' pk=order.pk as order_detail_url %}
{% bootstrap_button "Order details" icon="th-list" href=order_detail_url button_class="btn-primary btn-xs" %} {% bootstrap_button "Order details" icon="th-list" href=order_detail_url button_class="btn-primary btn-xs" %}
{% if not order.paid %}
{% url 'shop:order_cancel' pk=order.pk as order_cancel_url %}
{% bootstrap_button "Cancel order" icon="remove" href=order_cancel_url button_class="btn-danger btn-xs" %}
{% endif %}
</td> </td>
</tr> </tr>
{% endif %} {% endif %}

View file

@ -263,8 +263,15 @@ class OrderDetailView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureOrderH
if product_remove: if product_remove:
order.orderproductrelation_set.filter(pk=product_remove).delete() order.orderproductrelation_set.filter(pk=product_remove).delete()
if not order.products.count() > 0: if not order.products.count() > 0:
order.delete()
messages.info(request, 'Order cancelled!')
return HttpResponseRedirect(reverse_lazy('shop:index')) return HttpResponseRedirect(reverse_lazy('shop:index'))
if 'cancel_order' in request.POST:
order.delete()
messages.info(request, 'Order cancelled!')
return HttpResponseRedirect(reverse_lazy('shop:index'))
return super(OrderDetailView, self).get(request, *args, **kwargs) return super(OrderDetailView, self).get(request, *args, **kwargs)