2024-04-14 01:21:32 -04:00
|
|
|
from django.conf import settings
|
2024-05-16 00:58:17 -04:00
|
|
|
from django.core.mail import EmailMessage
|
2024-04-14 01:21:32 -04:00
|
|
|
|
2024-05-16 00:58:17 -04:00
|
|
|
from cmsmanage.email import TemplatedMultipartEmail
|
2024-04-14 01:21:32 -04:00
|
|
|
from membershipworks.models import EventInvoice
|
|
|
|
|
|
|
|
|
2024-05-16 00:58:17 -04:00
|
|
|
class InvoiceEmailBase(TemplatedMultipartEmail):
|
|
|
|
from_email = "CMS Invoices <invoices@claremontmakerspace.org>"
|
|
|
|
reply_to = ["Claremont MakerSpace <Info@ClaremontMakerSpace.org>"]
|
2024-04-14 01:21:32 -04:00
|
|
|
|
|
|
|
|
2024-05-16 00:58:17 -04:00
|
|
|
class InstructorInvoiceEmail(InvoiceEmailBase):
|
|
|
|
template = "membershipworks/email/event_invoice_instructor.dj.html"
|
2024-04-14 01:21:32 -04:00
|
|
|
|
2024-05-16 00:58:17 -04:00
|
|
|
@property
|
|
|
|
def subject(self) -> str:
|
|
|
|
event = self.context["invoice"].event
|
|
|
|
return f'Your CMS instructor invoice has been received for event "{event}" {event.start} - {event.end}'
|
2024-04-14 01:21:32 -04:00
|
|
|
|
2024-05-16 00:58:17 -04:00
|
|
|
@classmethod
|
|
|
|
def render_for_invoice(
|
|
|
|
cls, invoice: EventInvoice, pdf: bytes, event_url: str
|
|
|
|
) -> EmailMessage:
|
|
|
|
if invoice.event.instructor is None or invoice.event.instructor.member is None:
|
|
|
|
raise ValueError("Event Instructor not defined or is not member")
|
|
|
|
message = cls.render(
|
|
|
|
{"invoice": invoice, "event_url": event_url},
|
|
|
|
to=[invoice.event.instructor.member.sanitized_mailbox()],
|
|
|
|
)
|
|
|
|
message.attach(f"CMS_event_invoice_{invoice.uuid}.pdf", pdf, "application/pdf")
|
|
|
|
return message
|
2024-04-14 01:21:32 -04:00
|
|
|
|
|
|
|
|
2024-05-16 00:58:17 -04:00
|
|
|
class AdminInvoiceEmail(InvoiceEmailBase):
|
|
|
|
template = "membershipworks/email/event_invoice_admin.dj.html"
|
2024-04-14 01:21:32 -04:00
|
|
|
|
2024-05-16 00:58:17 -04:00
|
|
|
@property
|
|
|
|
def subject(self) -> str:
|
|
|
|
event = self.context["invoice"].event
|
|
|
|
return f'CMS instructor invoice created for event "{event}" {event.start} - {event.end}'
|
2024-04-14 01:21:32 -04:00
|
|
|
|
2024-05-16 00:58:17 -04:00
|
|
|
@classmethod
|
|
|
|
def render_for_invoice(
|
|
|
|
cls, invoice: EventInvoice, pdf: bytes, event_url: str
|
|
|
|
) -> EmailMessage:
|
|
|
|
message = cls.render(
|
|
|
|
{"invoice": invoice, "event_url": event_url},
|
|
|
|
# TODO: should this be in database instead?
|
|
|
|
to=settings.INVOICE_HANDLERS,
|
|
|
|
)
|
|
|
|
message.attach(f"CMS_event_invoice_{invoice.uuid}.pdf", pdf, "application/pdf")
|
|
|
|
return message
|
2024-04-14 01:21:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
def make_invoice_emails(
|
|
|
|
invoice: EventInvoice, pdf: bytes, event_url: str
|
|
|
|
) -> list[EmailMessage]:
|
|
|
|
return [
|
2024-05-16 00:58:17 -04:00
|
|
|
InstructorInvoiceEmail.render_for_invoice(invoice, pdf, event_url),
|
|
|
|
AdminInvoiceEmail.render_for_invoice(invoice, pdf, event_url),
|
2024-04-14 01:21:32 -04:00
|
|
|
]
|