Add receipt/invoice email support and option to Quay

This commit is contained in:
Joseph Schorr 2013-11-15 14:42:31 -05:00
parent 318dc79de3
commit 457b619647
14 changed files with 310 additions and 32 deletions

36
util/invoice.py Normal file
View file

@ -0,0 +1,36 @@
from datetime import datetime
from jinja2 import Environment, FileSystemLoader
jinja_options = {
"loader": FileSystemLoader('util'),
}
env = Environment(**jinja_options)
def renderInvoiceToHtml(invoice, user):
""" Renders a nice HTML display for the given invoice. """
def get_price(price):
if not price:
return '$0'
return '$' + '{.2f}'.format(price / 100)
def get_range(line):
if line.period and line.period.start and line.period.end:
return ': ' + format_date(line.period.start) + ' - ' + format_date(line.period.end)
return ''
def format_date(timestamp):
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d')
data = {
'user': user.username,
'invoice': invoice,
'invoice_date': format_date(invoice.date),
'getPrice': get_price,
'getRange': get_range
}
template = env.get_template('invoice.tmpl')
rendered = template.render(data)
return rendered