Refs #131 -- Basic implementation of invoicing

This commit is contained in:
Raphael Michel
2016-03-12 12:03:00 +01:00
parent 0f054416fc
commit 5ab78b4576
21 changed files with 1489 additions and 374 deletions

View File

@@ -91,43 +91,70 @@
{% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=False %}
</div>
</div>
{% if request.event.settings.invoice_address_asked %}
<div class="panel panel-primary">
<div class="panel-heading">
{% if order.can_modify_answers %}
<div class="pull-right">
<a href="{% eventurl event "presale:event.order.modify" secret=order.secret order=order.code %}">
<span class="fa fa-edit"></span>
{% trans "Change details" %}
</a>
<div class="row">
{% if invoices %}
<div class="col-xs-12 {% if request.event.settings.invoice_address_asked %}col-md-6{% endif %}">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
{% trans "Invoices" %}
</h3>
</div>
{% endif %}
<h3 class="panel-title">
{% trans "Invoice information" %}
</h3>
<div class="panel-body">
<ul>
{% for i in invoices %}
<li>
<a href="{% eventurl event "presale:event.invoice.download" invoice=i.pk secret=order.secret order=order.code %}">
{% if i.is_cancellation %}{% trans "Cancellation" %}{% else %}{% trans "Invoice" %}{% endif %}
{{ i.number }}</a> ({{ i.date|date:"SHORT_DATE_FORMAT" }})
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt>{% trans "Company" %}</dt>
<dd>{{ order.invoice_address.company }}</dd>
<dt>{% trans "Name" %}</dt>
<dd>{{ order.invoice_address.name }}</dd>
<dt>{% trans "Address" %}</dt>
<dd>{{ order.invoice_address.street|linebreaksbr }}</dd>
<dt>{% trans "ZIP code and city" %}</dt>
<dd>{{ order.invoice_address.zipcode }} {{ addr.city }}</dd>
<dt>{% trans "Country" %}</dt>
<dd>{{ order.invoice_address.country }}</dd>
<dt>{% trans "Phone" %}</dt>
<dd>{{ order.invoice_address.phone }}</dd>
{% if request.event.settings.invoice_address_vatid %}
<dt>{% trans "VAT ID" %}</dt>
<dd>{{ order.invoice_address.vat_id }}</dd>
{% endif %}
</dl>
{% endif %}
{% if request.event.settings.invoice_address_asked %}
<div class="col-xs-12 {% if invoices %}col-md-6{% endif %}">
<div class="panel panel-primary">
<div class="panel-heading">
{% if order.can_modify_answers %}
<div class="pull-right">
<a href="{% eventurl event "presale:event.order.modify" secret=order.secret order=order.code %}">
<span class="fa fa-edit"></span>
{% trans "Change details" %}
</a>
</div>
{% endif %}
<h3 class="panel-title">
{% trans "Invoice information" %}
</h3>
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt>{% trans "Company" %}</dt>
<dd>{{ order.invoice_address.company }}</dd>
<dt>{% trans "Name" %}</dt>
<dd>{{ order.invoice_address.name }}</dd>
<dt>{% trans "Address" %}</dt>
<dd>{{ order.invoice_address.street|linebreaksbr }}</dd>
<dt>{% trans "ZIP code and city" %}</dt>
<dd>{{ order.invoice_address.zipcode }} {{ addr.city }}</dd>
<dt>{% trans "Country" %}</dt>
<dd>{{ order.invoice_address.country }}</dd>
<dt>{% trans "Phone" %}</dt>
<dd>{{ order.invoice_address.phone }}</dd>
{% if request.event.settings.invoice_address_vatid %}
<dt>{% trans "VAT ID" %}</dt>
<dd>{{ order.invoice_address.vat_id }}</dd>
{% endif %}
</dl>
</div>
</div>
</div>
</div>
{% endif %}
{% endif %}
<div class="clearfix"></div>
</div>
{% if order.status == "n" %}
<div class="row">
<div class="col-md-12 text-right">

View File

@@ -35,6 +35,9 @@ event_patterns = [
url(r'^order/(?P<order>[^/]+)/(?P<secret>[A-Za-z0-9]+)/download/(?P<output>[^/]+)$',
pretix.presale.views.order.OrderDownload.as_view(),
name='event.order.download'),
url(r'^order/(?P<order>[^/]+)/(?P<secret>[A-Za-z0-9]+)/invoice/(?P<invoice>[^/]+)$',
pretix.presale.views.order.InvoiceDownload.as_view(),
name='event.invoice.download'),
url(r'^$', pretix.presale.views.event.EventIndex.as_view(), name='event.index'),
]

View File

@@ -9,8 +9,11 @@ from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from django.views.generic import TemplateView, View
from pretix.base.models import CachedFile, CachedTicket, Order, OrderPosition
from pretix.base.models import (
CachedFile, CachedTicket, Invoice, Order, OrderPosition,
)
from pretix.base.models.orders import InvoiceAddress
from pretix.base.services.invoices import invoice_pdf
from pretix.base.services.orders import cancel_order
from pretix.base.services.tickets import generate
from pretix.base.signals import (
@@ -85,6 +88,7 @@ class OrderDetails(EventViewMixin, OrderDetailMixin, CartMixin, TemplateView):
answers=True,
queryset=OrderPosition.objects.filter(order=self.order)
)
ctx['invoices'] = list(self.order.invoices.all())
if self.order.status == Order.STATUS_PENDING:
ctx['payment'] = self.payment_provider.order_pending_render(self.request, self.order)
ctx['can_retry'] = (
@@ -319,3 +323,31 @@ class OrderDownload(EventViewMixin, OrderDetailMixin, View):
ct.save()
generate(self.order.id, self.output.identifier)
return redirect(reverse('cachedfile.download', kwargs={'id': ct.cachedfile.id}))
class InvoiceDownload(EventViewMixin, OrderDetailMixin, View):
def get(self, request, *args, **kwargs):
if not self.order:
raise Http404(_('Unknown order code or not authorized to access this order.'))
try:
invoice = Invoice.objects.get(
event=self.request.event,
order=self.order,
id=self.kwargs['invoice']
)
except Invoice.DoesNotExist:
raise Http404(_('This invoice has not been found'))
if not invoice.file:
invoice_pdf(invoice.pk)
invoice = Invoice.objects.get(pk=invoice.pk)
if not invoice.file:
# This happens if we have celery installed and the file will be generated in the background
messages.warning(request, _('The invoice file has not yet been generated, we will generate it for you '
'now. Please try again in a few seconds.'))
return redirect(self.get_order_url())
return redirect(invoice.file.url)