membershipworks: Group tickets by price group for event invoices
All checks were successful
Ruff / ruff (push) Successful in 46s
Test / test (push) Successful in 3m44s

This groups tickets by their actual price grouping, instead of always
using member/non-member, which is not a useful distinction post 2024-07-01.
This commit is contained in:
Adam Goldsmith 2024-11-25 14:18:13 -05:00
parent fe03146bc6
commit ad93c361fd

View File

@ -704,11 +704,8 @@ class EventInvoice(models.Model):
class EventTicketTypeQuerySet(models.QuerySet["EventTicketType"]): class EventTicketTypeQuerySet(models.QuerySet["EventTicketType"]):
def group_by_ticket_type(self): def group_by_ticket_type(self):
return self.values(is_members_ticket=Q(restrict_to__isnull=False)).annotate( return self.values("price_group").annotate(
label=Case( label=F("price_group"),
When(Q(is_members_ticket=True), Value("Members")),
default=Value("Non-Members"),
),
actual_price=F("actual_price"), actual_price=F("actual_price"),
**{ **{
field: Sum(field) field: Sum(field)
@ -732,25 +729,31 @@ class EventTicketTypeManager(models.Manager["EventTicketType"]):
# restricted ticket, but list price for unrestricted # restricted ticket, but list price for unrestricted
# (Non-Members) ticket. After, use Members ticket price # (Non-Members) ticket. After, use Members ticket price
# for all tickets except where members ticket is free. # for all tickets except where members ticket is free.
actual_price=Case( price_group=Case(
When( When(
# member ticket Q(members_price=0)
Q(restrict_to__has_key=settings.MW_MEMBERS_FOLDER_ID) | Q(
| (
# non-member ticket
Q(restrict_to__isnull=True)
& (
Q(
event__start__lt=datetime( event__start__lt=datetime(
year=2024, year=2024,
month=7, month=7,
day=1, day=1,
tzinfo=timezone.get_default_timezone(), tzinfo=timezone.get_default_timezone(),
) )
)
| Q(members_price=0)
)
), ),
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", "list_price",
), ),
default="members_price", default="members_price",