Initial code to report VAT on invoices.

This commit is contained in:
Brett Smith 2019-11-11 14:30:05 -05:00
parent 24f5f97b24
commit b613a5072c
3 changed files with 26 additions and 1 deletions

View file

@ -1,6 +1,7 @@
import os import os
import dj_database_url import dj_database_url
from decimal import Decimal
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__)) PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
@ -315,6 +316,13 @@ TICKET_PRODUCT_CATEGORY = 1
INVOICE_CURRENCY = "USD" 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 = { MARKDOWN_DEUX_STYLES = {
"default": { "default": {
"safe_mode": False, "safe_mode": False,

View file

@ -38,6 +38,13 @@
{% endblock %} {% endblock %}
{% block extra_line_items_after_total %} {% 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 %} {% donation_income invoice as donation %}
{% if donation %} {% if donation %}
<tr> <tr>

View file

@ -11,6 +11,16 @@ from urllib import urlencode # TODO: s/urllib/six.moves.urllib/
register = template.Library() 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) @register.simple_tag(takes_context=True)
def donation_income(context, invoice): def donation_income(context, invoice):
@ -42,7 +52,7 @@ def donation_income(context, invoice):
rbi.append(line.total_price * fsa_rate) rbi.append(line.total_price * fsa_rate)
donation = max(Decimal('0'), (invoice.value - sum(rbi))) 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 # TODO: include van/de/van der/de la/etc etc etc