diff --git a/membershipworks/models.py b/membershipworks/models.py index eccdcb5..24b8342 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -704,11 +704,8 @@ class EventInvoice(models.Model): class EventTicketTypeQuerySet(models.QuerySet["EventTicketType"]): def group_by_ticket_type(self): - return self.values(is_members_ticket=Q(restrict_to__isnull=False)).annotate( - label=Case( - When(Q(is_members_ticket=True), Value("Members")), - default=Value("Non-Members"), - ), + return self.values("price_group").annotate( + label=F("price_group"), actual_price=F("actual_price"), **{ field: Sum(field) @@ -732,25 +729,31 @@ class EventTicketTypeManager(models.Manager["EventTicketType"]): # restricted ticket, but list price for unrestricted # (Non-Members) ticket. After, use Members ticket price # for all tickets except where members ticket is free. - actual_price=Case( + price_group=Case( When( - # member ticket - Q(restrict_to__has_key=settings.MW_MEMBERS_FOLDER_ID) - | ( - # non-member ticket - Q(restrict_to__isnull=True) - & ( - Q( - event__start__lt=datetime( - year=2024, - month=7, - day=1, - tzinfo=timezone.get_default_timezone(), - ) - ) - | Q(members_price=0) + Q(members_price=0) + | Q( + event__start__lt=datetime( + year=2024, + month=7, + day=1, + tzinfo=timezone.get_default_timezone(), ) ), + Case( + When(Q(restrict_to__isnull=True), Value("Non-Members")), + default=Value("Members"), + ), + ), + default=Value("Attendee"), + ), + actual_price=Case( + # Price group will be "Non-Members" iff we are using + # the list price for that ticket type. In all other + # cases (special program discounts or non-members + # tickets after 2024-07-01), use the members price + When( + Q(price_group=Value("Non-Members")), "list_price", ), default="members_price",