membershipworks: Add model and admin for EventInvoice

This commit is contained in:
Adam Goldsmith 2024-04-05 14:10:08 -04:00
parent 132b134dc5
commit b6b16a17d8
3 changed files with 62 additions and 1 deletions

View File

@ -14,6 +14,7 @@ from .models import (
Event,
EventExt,
EventInstructor,
EventInvoice,
EventMeetingTime,
Flag,
Member,
@ -119,9 +120,13 @@ class EventInstructorAdmin(admin.ModelAdmin):
search_fields = ["name", "member__account_name"]
class EventInvoiceInline(admin.StackedInline):
model = EventInvoice
@admin.register(EventExt)
class EventAdmin(DjangoObjectActions, admin.ModelAdmin):
inlines = [EventMeetingTimeInline]
inlines = [EventInvoiceInline, EventMeetingTimeInline]
list_display = [
"unescaped_title",
"start",

View File

@ -0,0 +1,41 @@
# Generated by Django 5.0.2 on 2024-03-08 21:30
import uuid
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("membershipworks", "0015_eventmeetingtime_end_after_start"),
]
operations = [
migrations.CreateModel(
name="EventInvoice",
fields=[
(
"uuid",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("date_submitted", models.DateField()),
("date_paid", models.DateField(blank=True, null=True)),
("pdf", models.FileField(upload_to="invoices/%Y/%m/%d/")),
("amount", models.DecimalField(decimal_places=4, max_digits=13)),
(
"event",
models.OneToOneField(
on_delete=django.db.models.deletion.PROTECT,
related_name="invoice",
to="membershipworks.eventext",
),
),
],
),
]

View File

@ -1,3 +1,4 @@
import uuid
from datetime import datetime
from typing import Optional
@ -576,6 +577,20 @@ class EventMeetingTime(models.Model):
]
class EventInvoice(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
event = models.OneToOneField(
EventExt, on_delete=models.PROTECT, related_name="invoice"
)
date_submitted = models.DateField()
date_paid = models.DateField(blank=True, null=True)
pdf = models.FileField(upload_to="protected/invoices/%Y/%m/%d/")
amount = models.DecimalField(max_digits=13, decimal_places=4)
def __str__(self) -> str:
return f'"{self.event}" submitted={self.date_submitted} paid:{self.date_paid} ${self.amount}'
class EventTicketTypeQuerySet(models.QuerySet["EventTicketType"]):
def group_by_ticket_type(self):
return self.values("is_members_ticket").annotate(