commit some more invoice stuff

This commit is contained in:
Thomas Steen Rasmussen 2016-05-30 18:09:21 +02:00
parent d8a1ec132b
commit 6f61220363
6 changed files with 89 additions and 9 deletions

View file

@ -8,9 +8,9 @@ def send_email(emailtype, recipient, formatdict, subject, sender='BornHack <nore
html_template=None html_template=None
if emailtype == 'invoice': if emailtype == 'invoice':
text_template = 'emails/invoice.txt' text_template = 'emails/invoice_email.txt'
html_template = 'emails/invoice.html' html_template = 'emails/invoice_email.html'
attachment_filename = formatdict['attachmentname'] attachment_filename = formatdict['filename']
elif emailtype == 'testmail': elif emailtype == 'testmail':
text_template = 'emails/testmail.txt' text_template = 'emails/testmail.txt'
else: else:
@ -25,7 +25,7 @@ def send_email(emailtype, recipient, formatdict, subject, sender='BornHack <nore
if html_template: if html_template:
msg.attach_alternative(render_to_string(html_template, formatdict), 'text/html') msg.attach_alternative(render_to_string(html_template, formatdict), 'text/html')
### is there an attachment to this mail? ### is there a pdf attachment to this mail?
if attachment: if attachment:
msg.attach(attachment_filename, attachment, 'application/pdf') msg.attach(attachment_filename, attachment, 'application/pdf')
@ -43,16 +43,17 @@ def send_email(emailtype, recipient, formatdict, subject, sender='BornHack <nore
def send_invoice_email(invoice, attachment): def send_invoice_email(invoice, attachment):
# put formatdict together # put formatdict together
formatdict = { formatdict = {
'order': invoice.order, 'ordernumber': invoice.order.pk,
'attachmentname': invoice.filename, 'invoicenumber': invoice.pk,
'filename': invoice.filename,
} }
subject = 'BornHack invoice %s' % order.pk subject = 'BornHack invoice %s' % invoice.pk
# send mail # send mail
return send_email( return send_email(
emailtype='invoice', emailtype='invoice',
recipient=order.user.email, recipient=invoice.order.user.email,
formatdict=formatdict, formatdict=formatdict,
subject=subject, subject=subject,
sender='noreply@bornfiber.dk', sender='noreply@bornfiber.dk',

View file

@ -24,6 +24,7 @@ class Command(BaseCommand):
formatdict = { formatdict = {
'invoice': invoice, 'invoice': invoice,
} }
# generate the pdf # generate the pdf
try: try:
pdffile = generate_pdf_letter( pdffile = generate_pdf_letter(
@ -35,6 +36,7 @@ class Command(BaseCommand):
except Exception as E: except Exception as E:
self.stdout.write('ERROR: Unable to generate PDF file for invoice #%s. Error: %s' % (invoice.pk, E)) self.stdout.write('ERROR: Unable to generate PDF file for invoice #%s. Error: %s' % (invoice.pk, E))
continue continue
# so, do we have a pdf? # so, do we have a pdf?
if not pdffile: if not pdffile:
self.stdout.write('ERROR: Unable to generate PDF file for invoice #%s' % invoice.pk) self.stdout.write('ERROR: Unable to generate PDF file for invoice #%s' % invoice.pk)
@ -61,4 +63,3 @@ class Command(BaseCommand):
### pause for a bit ### pause for a bit
sleep(60) sleep(60)

View file

@ -0,0 +1,16 @@
Hello!<br>
<br>
This email contains the invoice for your purchase from BornHack.<br>
Your order number is <b>{{ ordernumber }}</b> and your invoice number is <b>{{ invoicenumber }}</b>.<br>
<br>
Your order has been paid in full. The invoice is attached in PDF format with the filename <b>{{ filename }}</b>.<br>
<br>
Tickets will be generated closer to the event. Ticket holders will receive an email when tickets can be downloaded from the webshop. Merchandise can be picked up from the info booth during the event.<br>
<br>
Thank your for your purchase!<br>
<br>
<br>
Best regards,<br>
<br>
The BornHack Team<br>
<br>

View file

@ -0,0 +1,19 @@
Hello!
This email contains the invoice for your purchase from BornHack.
Your order number is {{ ordernumber }} and your invoice number is {{ invoicenumber }}.
Your order has been paid in full. The invoice is attached in PDF
format with the filename {{ filename }}.
Tickets will be generated closer to the event. Ticket
holders will receive an email when tickets can be downloaded
from the webshop. Merchandise can be picked up from the info
booth during the event.
Thank your for your purchase!
Best regards,
The BornHack Team

View file

@ -0,0 +1 @@
testmail from bornhack website

View file

@ -0,0 +1,42 @@
{% load shop_tags %}
This is an invoice.
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>
Name
<th>
Quantity
<th>
Price
<th>
Total
<tbody>
{% for order_product in invoice.order.orderproductrelation_set.all %}
<tr>
<td>
{{ order_product.product.name }}
<td>
{{ order_product.quantity }}
<td>
{{ order_product.product.price|currency }}
<td>
{{ order_product.total|currency }}
{% endfor %}
<tr>
<td colspan="2">
<td>
<strong>Hereof VAT (25%)</strong>
<td>
{{ order.vat|currency }}
<tr>
<td colspan="2">
<td>
<strong>Total</strong>
<td>
{{ order.total|currency }}
</table>