|
@@ -1,12 +1,13 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
from django.http import HttpResponse
|
|
|
from django.template import RequestContext
|
|
|
-from django.shortcuts import render, get_object_or_404, render_to_response
|
|
|
+from django.shortcuts import render, render_to_response
|
|
|
from django.core.exceptions import PermissionDenied
|
|
|
from coin.billing.models import Invoice
|
|
|
from coin.members.models import Member
|
|
|
from coin.html2pdf import render_as_pdf
|
|
|
from coin.billing.create_subscriptions_invoices import create_all_members_invoices_for_a_period
|
|
|
+from coin.billing.utils import get_invoice_from_id_or_number
|
|
|
|
|
|
def gen_invoices(request):
|
|
|
create_all_members_invoices_for_a_period()
|
|
@@ -17,20 +18,14 @@ def invoice_pdf(request, id):
|
|
|
Renvoi une facture générée en format pdf
|
|
|
id peut être soit la pk d'une facture, soit le numero de facture
|
|
|
"""
|
|
|
- try:
|
|
|
- invoice = Invoice.objects.get(pk=id)
|
|
|
- except:
|
|
|
- invoice = get_object_or_404(Invoice, number=id)
|
|
|
+
|
|
|
+ invoice = get_invoice_from_id_or_number(id)
|
|
|
|
|
|
if not invoice.has_owner(request.user.username)\
|
|
|
and not request.user.is_superuser:
|
|
|
raise PermissionDenied
|
|
|
|
|
|
- member = invoice.member
|
|
|
-
|
|
|
- context = {"invoice": invoice, 'member': member}
|
|
|
-
|
|
|
- pdf = render_as_pdf('billing/invoice_pdf.html', context)
|
|
|
+ pdf = render_as_pdf('billing/invoice_pdf.html', {"invoice": invoice})
|
|
|
|
|
|
response = HttpResponse(content_type='application/pdf')
|
|
|
#response['Content-Disposition'] = 'attachment; filename="facture.pdf"'
|
|
@@ -39,25 +34,21 @@ def invoice_pdf(request, id):
|
|
|
|
|
|
return response
|
|
|
|
|
|
-def invoice_html(request, id):
|
|
|
+def invoice(request, id):
|
|
|
"""
|
|
|
- Renvoi une facture générée en format pdf
|
|
|
+ Affiche une facture et son détail
|
|
|
id peut être soit la pk d'une facture, soit le numero de facture
|
|
|
"""
|
|
|
- try:
|
|
|
- invoice = Invoice.objects.get(pk=id)
|
|
|
- except:
|
|
|
- invoice = get_object_or_404(Invoice, number=id)
|
|
|
+ invoice = get_invoice_from_id_or_number(id)
|
|
|
|
|
|
if not invoice.has_owner(request.user.username)\
|
|
|
and not request.user.is_superuser:
|
|
|
raise PermissionDenied
|
|
|
|
|
|
- member = invoice.member
|
|
|
-
|
|
|
- context = {"invoice": invoice, 'member': member}
|
|
|
-
|
|
|
- return render_to_response('billing/invoice.html', context,
|
|
|
+ return render_to_response('billing/invoice.html', {"invoice": invoice},
|
|
|
context_instance=RequestContext(request))
|
|
|
|
|
|
return response
|
|
|
+
|
|
|
+
|
|
|
+
|