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"]):
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",