diff --git a/membershipworks/admin.py b/membershipworks/admin.py index a90997f..38d9347 100644 --- a/membershipworks/admin.py +++ b/membershipworks/admin.py @@ -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", diff --git a/membershipworks/migrations/0016_eventinvoice.py b/membershipworks/migrations/0016_eventinvoice.py new file mode 100644 index 0000000..d38891e --- /dev/null +++ b/membershipworks/migrations/0016_eventinvoice.py @@ -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", + ), + ), + ], + ), + ] diff --git a/membershipworks/models.py b/membershipworks/models.py index c954f80..462b664 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -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(