0 3 0
Brett Smith - 12 months 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:
↑ Collapse Diff ↑
1 1
 
import os
2 2
 
import dj_database_url
3 3
 

	
4
 
from decimal import Decimal
4 5
 

	
5 6
 
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
6 7
 
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
...
 
@@ -315,6 +316,13 @@ TICKET_PRODUCT_CATEGORY = 1
315 316
 

	
316 317
 
INVOICE_CURRENCY = "USD"
317 318
 

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

	
318 326
 
MARKDOWN_DEUX_STYLES = {
319 327
 
    "default": {
320 328
 
        "safe_mode": False,
...
 
@@ -38,6 +38,13 @@
38 38
 
{% endblock %}
39 39
 

	
40 40
 
{% block extra_line_items_after_total %}
41
 
  {% vat_amount(invoice) as vat %}
42
 
  {% if vat %}
43
 
    <tr>
44
 
      <td colspan="3">Includes {{ vat_rate }} VAT:</td>
45
 
      <td class="text-right">${{ vat }}</td>
46
 
    </tr>
47
 
  {% endif %}
41 48
 
  {% donation_income invoice as donation %}
42 49
 
  {% if donation %}
43 50
 
    <tr>
...
 
@@ -11,6 +11,16 @@ from urllib import urlencode  # TODO: s/urllib/six.moves.urllib/
11 11
 

	
12 12
 
register = template.Library()
13 13
 

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

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

	
21
 
@register.simple_tag
22
 
def vat_rate():
23
 
    return VAT_RATE
14 24
 

	
15 25
 
@register.simple_tag(takes_context=True)
16 26
 
def donation_income(context, invoice):
...
 
@@ -42,7 +52,7 @@ def donation_income(context, invoice):
42 52
 
            rbi.append(line.total_price * fsa_rate)
43 53
 

	
44 54
 
    donation = max(Decimal('0'), (invoice.value - sum(rbi)))
45
 
    return donation.quantize(Decimal('.01'))
55
 
    return donation.quantize(CENTS_QUANT)
46 56
 

	
47 57
 

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