templatetags: Update donation_income for CopyleftConf 2020.

This commit is contained in:
Brett Smith 2019-12-16 12:26:11 -05:00
parent 9af0cce802
commit 9d5f83ec39

View file

@ -1,4 +1,4 @@
from registrasion.models import commerce
from registrasion.models import commerce, inventory
from registrasion.controllers.category import CategoryController
from registrasion.controllers.item import ItemController
from registrasion.templatetags import registrasion_tags
@ -14,6 +14,9 @@ register = template.Library()
CENTS_QUANT = Decimal('.01')
VAT_RATE = str(settings.INVOICE_VAT_RATE * 100).rstrip('.0') + '%'
def nonvat_price(product):
return product.price * (1 - settings.INVOICE_VAT_RATE)
@register.simple_tag
def vat_amount(invoice):
return (invoice.value * settings.INVOICE_VAT_RATE).quantize(CENTS_QUANT)
@ -31,28 +34,13 @@ def donation_income(context, invoice):
'''
# 15% (FSA) goes to Conservancy; 85% is real goods
fsa_rate = Decimal("0.85")
rbi_full_ticket = Decimal("68.00")
rbi_early_bird_discount = Decimal("-21.35")
rbi = []
for line in invoice.lineitem_set.all():
if line.product.category.name == "Ticket":
if line.product.name.startswith("Unaffiliated Individual"):
# Includes full price & discounts
rbi.append(line.total_price * fsa_rate)
else:
if line.total_price > 0:
rbi.append(rbi_full_ticket)
elif line.total_price < 0:
rbi.append(rbi_early_bird_discount)
elif line.product.category.name == "T-Shirt":
rbi.append(line.total_price * fsa_rate)
donation = max(Decimal('0'), (invoice.value - sum(rbi)))
return donation.quantize(CENTS_QUANT)
tickets = inventory.Product.objects.filter(category__id=settings.TICKET_PRODUCT_CATEGORY)
cheapest_ticket = tickets.order_by('price').first()
ticket_rbi = nonvat_price(cheapest_ticket)
return sum(
(nonvat_price(ticket) - ticket_rbi
for ticket in invoice.lineitem_set.filter(product__in=tickets)),
Decimal(0)).quantize(CENTS_QUANT)
# TODO: include van/de/van der/de la/etc etc etc