Last active
September 13, 2018 12:41
-
-
Save harshvb7/0554e1dd0980a73aa4bc8b8052741d6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_reserved_tickets(self, performance=None): | |
Offer = apps.get_model('events', 'Offer') | |
Order = apps.get_model('events', 'Order') | |
offers = Offer.objects.published().filter( | |
state=1, | |
ticket_price=self, | |
) | |
if performance: | |
offers = offers.filter(performance=performance) | |
pending_tickets = offers.filter(basket__state=0).distinct() \ | |
.aggregate(count=models.Sum('quantity'))['count'] | |
pending_tickets = pending_tickets if pending_tickets else 0 | |
booked_tickets = offers = offers.filter(basket__state=1) \ | |
.values_list('basket_id', flat=True) | |
booked_tickets = Order.objects \ | |
.filter(state=1, basket_id__in=list(booked_tickets)) \ | |
.aggregate(count=models.Sum('tickets_count'))['count'] | |
booked_tickets = booked_tickets if booked_tickets else 0 | |
return pending_tickets + booked_tickets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment