Changeset - b613a5072cbd
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2019-11-11 19:30:05
brettcsmith@brettcsmith.org
Initial code to report VAT on invoices.
3 files changed with 26 insertions and 1 deletions:
0 comments (0 inline, 0 general)
pinaxcon/settings.py
Show inline comments
 
import os
 
import dj_database_url
 

	
 
from decimal import Decimal
 

	
 
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
 
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
 
BASE_DIR = PACKAGE_ROOT
 

	
 
DEBUG = bool(int(os.environ.get("DJANGO_DEBUG", "1")))
...
 
@@ -312,12 +313,19 @@ ATTENDEE_PROFILE_MODEL = "pinaxcon.registrasion.models.AttendeeProfile"
 
# Ticket product category -- used to identify which products must be available
 
# in order to register.
 
TICKET_PRODUCT_CATEGORY = 1
 

	
 
INVOICE_CURRENCY = "USD"
 

	
 
# VAT rate is 21%
 
# When PINAX_VAT_RATE is set, this percentage of the invoice total is
 
# displayed as a line item as the amount of VAT paid.
 
INVOICE_VAT_RATE = Decimal(os.environ.get('PINAX_VAT_RATE') or 0)
 
if INVOICE_VAT_RATE > 1:
 
    INVOICE_VAT_RATE /= 100
 

	
 
MARKDOWN_DEUX_STYLES = {
 
    "default": {
 
        "safe_mode": False,
 
        "extras": {
 
            "tables": 1,
 
        }
pinaxcon/templates/registrasion/invoice/details.html
Show inline comments
...
 
@@ -35,12 +35,19 @@
 
  {% elif invoice.is_paid %}
 
    This is a confirmed registration summary for CopyleftConf 2020.
 
  {% endif %}
 
{% endblock %}
 

	
 
{% block extra_line_items_after_total %}
 
  {% vat_amount(invoice) as vat %}
 
  {% if vat %}
 
    <tr>
 
      <td colspan="3">Includes {{ vat_rate }} VAT:</td>
 
      <td class="text-right">${{ vat }}</td>
 
    </tr>
 
  {% endif %}
 
  {% donation_income invoice as donation %}
 
  {% if donation %}
 
    <tr>
 
      <td colspan="3">Includes donation eligible for tax deduction in the USA:</td>
 
      <td class="text-right">${{ donation }}</td>
 
    </tr>
pinaxcon/templatetags/nbpy_tags.py
Show inline comments
...
 
@@ -8,12 +8,22 @@ from django import template
 
from django.conf import settings
 
from django.db.models import Sum
 
from urllib import urlencode  # TODO: s/urllib/six.moves.urllib/
 

	
 
register = template.Library()
 

	
 
CENTS_QUANT = Decimal('.01')
 
VAT_RATE = str(settings.INVOICE_VAT_RATE * 100).rstrip('.0') + '%'
 

	
 
@register.simple_tag
 
def vat_amount(invoice):
 
    return (invoice.value * settings.INVOICE_VAT_RATE).quantize(CENTS_QUANT)
 

	
 
@register.simple_tag
 
def vat_rate():
 
    return VAT_RATE
 

	
 
@register.simple_tag(takes_context=True)
 
def donation_income(context, invoice):
 
    ''' Calculates the donation income for a given invoice.
 

	
 
    Returns:
...
 
@@ -39,13 +49,13 @@ def donation_income(context, invoice):
 
                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(Decimal('.01'))
 
    return donation.quantize(CENTS_QUANT)
 

	
 

	
 
# TODO: include van/de/van der/de la/etc etc etc
 

	
 
@register.simple_tag
 
def name_split(name, split_characters=None):
0 comments (0 inline, 0 general)