membershipworks: Use monospace font for invoice header math

This commit is contained in:
Adam Goldsmith 2024-03-04 15:53:53 -05:00
parent 1ac1470d29
commit 0318a610e7

View File

@ -8,6 +8,8 @@ from django.db.models import OuterRef, Q, Subquery
from django.db.models.functions import TruncMonth, TruncYear from django.db.models.functions import TruncMonth, TruncYear
from django.shortcuts import render from django.shortcuts import render
from django.template.defaultfilters import floatformat from django.template.defaultfilters import floatformat
from django.utils.html import format_html
from django.utils.safestring import SafeString
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
from django.views.generic.dates import ( from django.views.generic.dates import (
ArchiveIndexView, ArchiveIndexView,
@ -299,17 +301,34 @@ class InvoiceTable(tables.Table):
self.event = kwargs.pop("event") self.event = kwargs.pop("event")
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@staticmethod
def _math_header(name: str, formula: str) -> SafeString:
return format_html(
'{} <div class="text-nowrap font-monospace fw-light">[{}]</div>',
name,
formula,
)
label = tables.Column("Ticket Type", footer="Subtotals") label = tables.Column("Ticket Type", footer="Subtotals")
list_price = InvoiceMoneyColumn("Ticket Price") list_price = InvoiceMoneyColumn("Ticket Price")
actual_price = InvoiceMoneyColumn("Actual Price [P]") actual_price = InvoiceMoneyColumn(_math_header("Actual Price", "P"))
quantity = tables.Column("Quantity [Q]", footer=lambda table: table.event.quantity) quantity = tables.Column(
amount = InvoiceMoneyFooterColumn("Amount [A = P * Q]") _math_header("Quantity", "Q"),
materials = InvoiceMoneyFooterColumn("CMS Collected Materials Fee [M = m * Q]") footer=lambda table: table.event.quantity,
amount_without_materials = InvoiceMoneyFooterColumn( )
"Event Revenue Base [B = A - M]" amount = InvoiceMoneyFooterColumn(_math_header("Amount", "A=P*Q"))
materials = InvoiceMoneyFooterColumn(
_math_header("CMS Collected Materials Fee", "M=m*Q")
)
amount_without_materials = InvoiceMoneyFooterColumn(
_math_header("Event Revenue Base", "B=A-M")
)
instructor_revenue = InvoiceMoneyFooterColumn(
_math_header("Instructor Percentage Revenue", "R=B*I")
)
instructor_amount = InvoiceMoneyFooterColumn(
_math_header("Amount Due to Instructor", "R+M")
) )
instructor_revenue = InvoiceMoneyFooterColumn("Instructor Revenue [R = B * I]")
instructor_amount = InvoiceMoneyFooterColumn("Amount Due to Instructor [R + M]")
class Meta: class Meta:
attrs = { attrs = {