|
@@ -4,7 +4,6 @@ from __future__ import unicode_literals
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
|
from django.template import RequestContext
|
|
from django.template import RequestContext
|
|
from django.shortcuts import render, render_to_response
|
|
from django.shortcuts import render, render_to_response
|
|
-from django.core.exceptions import PermissionDenied
|
|
|
|
from django.contrib import messages
|
|
from django.contrib import messages
|
|
|
|
|
|
from sendfile import sendfile
|
|
from sendfile import sendfile
|
|
@@ -13,7 +12,7 @@ from coin.billing.models import Invoice
|
|
from coin.members.models import Member
|
|
from coin.members.models import Member
|
|
from coin.html2pdf import render_as_pdf
|
|
from coin.html2pdf import render_as_pdf
|
|
from coin.billing.create_subscriptions_invoices import create_all_members_invoices_for_a_period
|
|
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
|
|
|
|
|
|
+from coin.billing.utils import get_invoice_from_id_or_number, assert_user_can_view_the_invoice
|
|
|
|
|
|
|
|
|
|
def gen_invoices(request):
|
|
def gen_invoices(request):
|
|
@@ -28,9 +27,7 @@ def invoice_pdf(request, id):
|
|
"""
|
|
"""
|
|
invoice = get_invoice_from_id_or_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
|
|
|
|
|
|
+ assert_user_can_view_the_invoice(request, invoice)
|
|
|
|
|
|
pdf_filename = 'Facture_%s.pdf' % invoice.number
|
|
pdf_filename = 'Facture_%s.pdf' % invoice.number
|
|
|
|
|
|
@@ -45,9 +42,7 @@ def invoice(request, id):
|
|
"""
|
|
"""
|
|
invoice = get_invoice_from_id_or_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
|
|
|
|
|
|
+ assert_user_can_view_the_invoice(request, invoice)
|
|
|
|
|
|
return render_to_response('billing/invoice.html', {"invoice": invoice},
|
|
return render_to_response('billing/invoice.html', {"invoice": invoice},
|
|
context_instance=RequestContext(request))
|
|
context_instance=RequestContext(request))
|