mark orderproductrelations as handed_out=True when Ticket objects have been created

This commit is contained in:
Thomas Steen Rasmussen 2017-10-03 23:45:22 +02:00
parent c914c23117
commit e0e65212bc
2 changed files with 9 additions and 3 deletions

View file

@ -97,7 +97,7 @@ class OrderAdmin(admin.ModelAdmin):
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):
order.mark_as_paid() order.mark_as_paid(request)
mark_order_as_paid.description = 'Mark order(s) as paid' mark_order_as_paid.description = 'Mark order(s) as paid'
def mark_order_as_refunded(self, request, queryset): def mark_order_as_refunded(self, request, queryset):

View file

@ -185,11 +185,13 @@ class Order(CreatedUpdatedModel):
def get_absolute_url(self): def get_absolute_url(self):
return str(reverse_lazy('shop:order_detail', kwargs={'pk': self.pk})) return str(reverse_lazy('shop:order_detail', kwargs={'pk': self.pk}))
def mark_as_paid(self): def mark_as_paid(self, request):
self.paid = True self.paid = True
self.open = None self.open = None
for order_product in self.orderproductrelation_set.all(): for order_product in self.orderproductrelation_set.all():
if order_product.product.category.name == "Tickets": # if this is a Ticket product?
if order_product.product.ticket_type:
# create the number of tickets required
for _ in range(0, order_product.quantity): for _ in range(0, order_product.quantity):
ticket = ShopTicket( ticket = ShopTicket(
ticket_type=order_product.product.ticket_type, ticket_type=order_product.product.ticket_type,
@ -197,6 +199,10 @@ class Order(CreatedUpdatedModel):
product=order_product.product, product=order_product.product,
) )
ticket.save() ticket.save()
messages.success(request, "Created %s tickets of type: %s" % (order_product.quantity, order_product.product.ticket_type.name))
# and mark the OPR as handed_out=True
order_product.handed_out=True
order_product.save()
self.save() self.save()
def mark_as_refunded(self, request): def mark_as_refunded(self, request):