membershipworks: Use more consistent and readable format for money columns
This commit is contained in:
parent
9198503572
commit
56f49f8784
@ -21,6 +21,23 @@ class DurationColumn(tables.Column):
|
|||||||
return value.total_seconds() / 60 / 60
|
return value.total_seconds() / 60 / 60
|
||||||
|
|
||||||
|
|
||||||
|
class MoneyColumn(tables.columns.Column):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.attrs["cell"] = {"class": "text-end", **self.attrs.get("cell", {})}
|
||||||
|
|
||||||
|
def render(self, value) -> str:
|
||||||
|
return f"{super().render(value):.2f}"
|
||||||
|
|
||||||
|
def value(self, **kwargs):
|
||||||
|
return kwargs["value"]
|
||||||
|
|
||||||
|
|
||||||
|
class CurrencySymbolMoneyColumn(MoneyColumn):
|
||||||
|
def render(self, value) -> str:
|
||||||
|
return f"${super().render(value)}"
|
||||||
|
|
||||||
|
|
||||||
class EventTable(tables.Table):
|
class EventTable(tables.Table):
|
||||||
title = tables.TemplateColumn(
|
title = tables.TemplateColumn(
|
||||||
template_code=(
|
template_code=(
|
||||||
@ -36,9 +53,9 @@ class EventTable(tables.Table):
|
|||||||
duration = DurationColumn()
|
duration = DurationColumn()
|
||||||
person_hours = DurationColumn()
|
person_hours = DurationColumn()
|
||||||
meetings = tables.Column()
|
meetings = tables.Column()
|
||||||
gross_revenue = tables.Column()
|
gross_revenue = MoneyColumn()
|
||||||
total_due_to_instructor = tables.Column()
|
total_due_to_instructor = MoneyColumn()
|
||||||
net_revenue = tables.Column()
|
net_revenue = MoneyColumn()
|
||||||
invoice__date_submitted = tables.DateColumn(verbose_name="Invoice Submitted")
|
invoice__date_submitted = tables.DateColumn(verbose_name="Invoice Submitted")
|
||||||
invoice__date_paid = tables.DateColumn(verbose_name="Invoice Paid")
|
invoice__date_paid = tables.DateColumn(verbose_name="Invoice Paid")
|
||||||
|
|
||||||
@ -103,9 +120,9 @@ class EventSummaryTable(tables.Table):
|
|||||||
meetings__sum = tables.Column("Meetings")
|
meetings__sum = tables.Column("Meetings")
|
||||||
duration__sum = DurationColumn("Class Hours")
|
duration__sum = DurationColumn("Class Hours")
|
||||||
person_hours__sum = DurationColumn("Person Hours")
|
person_hours__sum = DurationColumn("Person Hours")
|
||||||
gross_revenue__sum = tables.Column("Gross Revenue")
|
gross_revenue__sum = MoneyColumn("Gross Revenue")
|
||||||
total_due_to_instructor__sum = tables.Column("Total Due to Instructor")
|
total_due_to_instructor__sum = MoneyColumn("Total Due to Instructor")
|
||||||
net_revenue__sum = tables.Column("Net Revenue")
|
net_revenue__sum = MoneyColumn("Net Revenue")
|
||||||
|
|
||||||
|
|
||||||
class UserEventTable(EventTable):
|
class UserEventTable(EventTable):
|
||||||
@ -136,12 +153,7 @@ class CurrentAndUpcomingEventTable(EventTable):
|
|||||||
sequence = ("title", "start", "next_meeting")
|
sequence = ("title", "start", "next_meeting")
|
||||||
|
|
||||||
|
|
||||||
class InvoiceMoneyColumn(tables.columns.Column):
|
class MoneyFooterColumn(MoneyColumn):
|
||||||
def render(self, value):
|
|
||||||
return f"${super().render(value):.2f}"
|
|
||||||
|
|
||||||
|
|
||||||
class InvoiceMoneyFooterColumn(InvoiceMoneyColumn):
|
|
||||||
def render_footer(self, bound_column, table):
|
def render_footer(self, bound_column, table):
|
||||||
value = getattr(table.event, bound_column.accessor)
|
value = getattr(table.event, bound_column.accessor)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
@ -164,23 +176,23 @@ class InvoiceTable(tables.Table):
|
|||||||
)
|
)
|
||||||
|
|
||||||
label = tables.Column("Ticket Type", footer="Subtotals")
|
label = tables.Column("Ticket Type", footer="Subtotals")
|
||||||
list_price = InvoiceMoneyColumn("Ticket Price")
|
list_price = CurrencySymbolMoneyColumn("Ticket Price")
|
||||||
actual_price = InvoiceMoneyColumn(_math_header("Actual Price", "P"))
|
actual_price = CurrencySymbolMoneyColumn(_math_header("Actual Price", "P"))
|
||||||
quantity = tables.Column(
|
quantity = tables.Column(
|
||||||
_math_header("Quantity", "Q"),
|
_math_header("Quantity", "Q"),
|
||||||
footer=lambda table: table.event.quantity,
|
footer=lambda table: table.event.quantity,
|
||||||
)
|
)
|
||||||
amount = InvoiceMoneyFooterColumn(_math_header("Amount", "A=P*Q"))
|
amount = CurrencySymbolMoneyColumn(_math_header("Amount", "A=P*Q"))
|
||||||
materials = InvoiceMoneyFooterColumn(
|
materials = CurrencySymbolMoneyColumn(
|
||||||
_math_header("CMS Collected Materials Fee", "M=m*Q")
|
_math_header("CMS Collected Materials Fee", "M=m*Q")
|
||||||
)
|
)
|
||||||
amount_without_materials = InvoiceMoneyFooterColumn(
|
amount_without_materials = CurrencySymbolMoneyColumn(
|
||||||
_math_header("Event Revenue Base", "B=A-M")
|
_math_header("Event Revenue Base", "B=A-M")
|
||||||
)
|
)
|
||||||
instructor_revenue = InvoiceMoneyFooterColumn(
|
instructor_revenue = CurrencySymbolMoneyColumn(
|
||||||
_math_header("Instructor Percentage Revenue", "R=B*I")
|
_math_header("Instructor Percentage Revenue", "R=B*I"),
|
||||||
)
|
)
|
||||||
instructor_amount = InvoiceMoneyFooterColumn(
|
instructor_amount = CurrencySymbolMoneyColumn(
|
||||||
_math_header("Amount Due to Instructor", "R+M")
|
_math_header("Amount Due to Instructor", "R+M")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user