0 1 0
Brett Smith - 11 months ago 2019-12-16 17:26:11
brettcsmith@brettcsmith.org
templatetags: Update donation_income for CopyleftConf 2020.
1 file changed with 11 insertions and 23 deletions:
↑ Collapse Diff ↑
1
 
from registrasion.models import commerce
1
 
from registrasion.models import commerce, inventory
2 2
 
from registrasion.controllers.category import CategoryController
3 3
 
from registrasion.controllers.item import ItemController
4 4
 
from registrasion.templatetags import registrasion_tags
...
 
@@ -14,6 +14,9 @@ register = template.Library()
14 14
 
CENTS_QUANT = Decimal('.01')
15 15
 
VAT_RATE = str(settings.INVOICE_VAT_RATE * 100).rstrip('.0') + '%'
16 16
 

	
17
 
def nonvat_price(product):
18
 
    return product.price * (1 - settings.INVOICE_VAT_RATE)
19
 

	
17 20
 
@register.simple_tag
18 21
 
def vat_amount(invoice):
19 22
 
    return (invoice.value * settings.INVOICE_VAT_RATE).quantize(CENTS_QUANT)
...
 
@@ -31,28 +34,13 @@ def donation_income(context, invoice):
31 34
 

	
32 35
 
    '''
33 36
 

	
34
 
    # 15% (FSA) goes to Conservancy; 85% is real goods
35
 

	
36
 
    fsa_rate = Decimal("0.85")
37
 
    rbi_full_ticket = Decimal("68.00")
38
 
    rbi_early_bird_discount = Decimal("-21.35")
39
 
    rbi = []
40
 

	
41
 
    for line in invoice.lineitem_set.all():
42
 
        if line.product.category.name == "Ticket":
43
 
            if line.product.name.startswith("Unaffiliated Individual"):
44
 
                # Includes full price & discounts
45
 
                rbi.append(line.total_price * fsa_rate)
46
 
            else:
47
 
                if line.total_price > 0:
48
 
                    rbi.append(rbi_full_ticket)
49
 
                elif line.total_price < 0:
50
 
                    rbi.append(rbi_early_bird_discount)
51
 
        elif line.product.category.name == "T-Shirt":
52
 
            rbi.append(line.total_price * fsa_rate)
53
 

	
54
 
    donation = max(Decimal('0'), (invoice.value - sum(rbi)))
55
 
    return donation.quantize(CENTS_QUANT)
37
 
    tickets = inventory.Product.objects.filter(category__id=settings.TICKET_PRODUCT_CATEGORY)
38
 
    cheapest_ticket = tickets.order_by('price').first()
39
 
    ticket_rbi = nonvat_price(cheapest_ticket)
40
 
    return sum(
41
 
        (nonvat_price(ticket) - ticket_rbi
42
 
         for ticket in invoice.lineitem_set.filter(product__in=tickets)),
43
 
        Decimal(0)).quantize(CENTS_QUANT)
56 44
 

	
57 45
 

	
58 46
 
# TODO: include van/de/van der/de la/etc etc etc
0 comments (0 inline, 0 general)