Marking an Order as paid should generate Tickets

This commit is contained in:
Víðir Valberg Guðmundsson 2016-05-25 20:05:31 +02:00
parent ff4f42bbdc
commit c0045177aa
4 changed files with 33 additions and 1 deletions

View file

@ -98,3 +98,5 @@ BOOTSTRAP3 = {
EPAY_MERCHANT_NUMBER = env('EPAY_MERCHANT_NUMBER') EPAY_MERCHANT_NUMBER = env('EPAY_MERCHANT_NUMBER')
EPAY_MD5_SECRET = env('EPAY_MD5_SECRET') EPAY_MD5_SECRET = env('EPAY_MD5_SECRET')
TICKET_CATEGORY_ID = env('TICKET_CATEGORY_ID')

View file

@ -9,3 +9,4 @@ EMAIL_USE_TLS=True
EMAIL_FROM='noreply@example.com' EMAIL_FROM='noreply@example.com'
EPAY_MERCHANT_NUMBER=something EPAY_MERCHANT_NUMBER=something
EPAY_MD5_SECRET=something EPAY_MD5_SECRET=something
TICKET_CATEGORY_ID=''

View file

@ -27,6 +27,13 @@ class ProductInline(admin.TabularInline):
model = models.OrderProductRelation model = models.OrderProductRelation
class TicketInline(admin.TabularInline):
model = models.Ticket
exclude = ['qrcode_base64']
@admin.register(models.Order) @admin.register(models.Order)
class OrderAdmin(admin.ModelAdmin): class OrderAdmin(admin.ModelAdmin):
list_display = [ list_display = [
@ -45,7 +52,14 @@ class OrderAdmin(admin.ModelAdmin):
exclude = ['products'] exclude = ['products']
inlines = [ProductInline] inlines = [ProductInline, TicketInline]
actions = ['mark_order_as_paid']
def mark_order_as_paid(self, request, queryset):
for order in queryset.filter(paid=False):
order.mark_as_paid()
mark_order_as_paid.description = 'Mark order(s) as paid'
@admin.register(models.Ticket) @admin.register(models.Ticket)

View file

@ -105,6 +105,21 @@ 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):
self.paid = True
for order_product in self.orderproductrelation_set.all():
category_pk = str(order_product.product.category.pk)
print(order_product, category_pk, settings.TICKET_CATEGORY_ID)
if category_pk == settings.TICKET_CATEGORY_ID:
for _ in range(0, order_product.quantity):
ticket = Ticket(
order=self,
product=order_product.product,
)
ticket.save()
self.save()
class ProductCategory(CreatedUpdatedModel, UUIDModel): class ProductCategory(CreatedUpdatedModel, UUIDModel):
class Meta: class Meta: