add mass order cancel adminaction

This commit is contained in:
Thomas Steen Rasmussen 2019-03-17 15:04:28 +01:00
parent 53adb50baf
commit 481a7d1a95
2 changed files with 13 additions and 1 deletions

View file

@ -163,7 +163,7 @@ class OrderAdmin(admin.ModelAdmin):
inlines = [ProductInline, ShopTicketInline] inlines = [ProductInline, ShopTicketInline]
actions = ['mark_order_as_paid', 'mark_order_as_refunded'] actions = ['mark_order_as_paid', 'mark_order_as_refunded', 'mark_order_as_cancelled']
def mark_order_as_paid(self, request, queryset): def mark_order_as_paid(self, request, queryset):
for order in queryset.filter(paid=False): for order in queryset.filter(paid=False):
@ -175,6 +175,11 @@ class OrderAdmin(admin.ModelAdmin):
order.mark_as_refunded(request) order.mark_as_refunded(request)
mark_order_as_refunded.description = 'Mark order(s) as refunded' mark_order_as_refunded.description = 'Mark order(s) as refunded'
def mark_order_as_cancelled(self, request, queryset):
for order in queryset.filter(cancelled=False):
order.mark_as_cancelled(request)
mark_order_as_cancelled.description = 'Mark order(s) as cancelled'
def get_user_email(obj): def get_user_email(obj):
return obj.order.user.email return obj.order.user.email

View file

@ -227,6 +227,13 @@ class Order(CreatedUpdatedModel):
messages.success(request, "Order %s marked as refunded, no tickets to delete" % self.pk) messages.success(request, "Order %s marked as refunded, no tickets to delete" % self.pk)
self.save() self.save()
def mark_as_cancelled(self, request):
if self.paid:
messages.error(request, "Order %s is paid, cannot cancel a paid order!" % self.pk)
else:
self.cancelled = True
self.save()
def is_not_handed_out(self): def is_not_handed_out(self):
if self.orderproductrelation_set.filter(handed_out=True).count() == 0: if self.orderproductrelation_set.filter(handed_out=True).count() == 0:
return True return True