diff --git a/cotisations/models.py b/cotisations/models.py
index 69ff45d1..aa002c33 100644
--- a/cotisations/models.py
+++ b/cotisations/models.py
@@ -14,6 +14,9 @@ class Facture(models.Model):
prix = Vente.objects.all().filter(facture=self).aggregate(models.Sum('prix'))['prix__sum']
return prix
+ def prix_total(self):
+ return self.prix()*self.number
+
def name(self):
name = ' - '.join(vente.name for vente in Vente.objects.all().filter(facture=self))
return name
diff --git a/cotisations/templates/cotisations/aff_cotisations.html b/cotisations/templates/cotisations/aff_cotisations.html
index c33063f7..54080588 100644
--- a/cotisations/templates/cotisations/aff_cotisations.html
+++ b/cotisations/templates/cotisations/aff_cotisations.html
@@ -8,6 +8,7 @@
Moyen de paiement |
Date |
|
+ |
{% for facture in facture_list %}
@@ -19,6 +20,7 @@
{{ facture.paiement }} |
{{ facture.date }} |
{% if is_cableur %} Editer{% endif %} |
+ PDF |
{% endfor %}
diff --git a/cotisations/templates/cotisations/factures.tex b/cotisations/templates/cotisations/factures.tex
index aaaf42e8..acead159 100644
--- a/cotisations/templates/cotisations/factures.tex
+++ b/cotisations/templates/cotisations/factures.tex
@@ -54,8 +54,8 @@
%----------------------------------------------------------------------------------------
\begin{titlepage}
%\begin{textblock}{4cm}(20mm,5mm)
-%\includegraphics[scale=0.3]{% templatetag openbrace %}{{tpl_path}}/logo.png}
-%\end{textblock}
+%\includegraphics[scale=0.3]{/static_files/rezo-logo.png}
+%\end{textblock}
\end{titlepage}
\hfil{\Huge\bf {{asso_name}} }\hfil % Company providing the invoice
\bigskip\break % Whitespace
@@ -65,12 +65,12 @@
{{line2}} \hfill {{email}} \\
Siret : {{siret}}
\\ \\
-{\bf À :} \tab {{dest}} \\ % Invoice recipient
+{\bf À :} \tab {{dest.name}} {{dest.surname}} \\ % Invoice recipient
+{\bf Chambre :} \tab {% if dest.room = None %} Aucune chambre {% else %}{{dest.room}}{% endif %} \\
{\bf Date:} \tab {{DATE}} \\ % Invoice date
-{\bf Objet:} \tab {{obj}} \\ % Objet
-\tab \tab {{detail}} \\ % Details
+{\bf Facture \no :} \tab {{ fid }} \\ %
%----------------------------------------------------------------------------------------
% TABLE OF EXPENSES
%----------------------------------------------------------------------------------------
@@ -107,6 +107,7 @@ Siret : {{siret}}
\vspace{1.5cm} % Whitespace
\hrule % Horizontal line
+\vspace{0.25cm}
\footnotesize{TVA non applicable, art. 293 B du CGI}
{% endlanguage %}
diff --git a/cotisations/urls.py b/cotisations/urls.py
index 56d090e2..24b8dc5a 100644
--- a/cotisations/urls.py
+++ b/cotisations/urls.py
@@ -5,6 +5,7 @@ from . import views
urlpatterns = [
url(r'^new_facture/(?P[0-9]+)$', views.new_facture, name='new-facture'),
url(r'^edit_facture/(?P[0-9]+)$', views.edit_facture, name='edit-facture'),
+ url(r'^facture_pdf/(?P[0-9]+)$', views.facture_pdf, name='facture-pdf'),
url(r'^new_facture_pdf/$', views.new_facture_pdf, name='new-facture-pdf'),
url(r'^add_article/$', views.add_article, name='add-article'),
url(r'^edit_article/(?P[0-9]+)$', views.edit_article, name='edit-article'),
diff --git a/cotisations/views.py b/cotisations/views.py
index 3cb724ea..772319aa 100644
--- a/cotisations/views.py
+++ b/cotisations/views.py
@@ -13,7 +13,7 @@ from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf
from users.models import User
from .tex import render_tex
-from re2o.settings import ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE
+from re2o.settings_local import ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH
from dateutil.relativedelta import relativedelta
from django.utils import timezone
@@ -61,6 +61,7 @@ def new_facture(request, userid):
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
@login_required
+@permission_required('cableur')
def new_facture_pdf(request):
facture_form = NewFactureFormPdf(request.POST or None)
if facture_form.is_valid():
@@ -77,6 +78,22 @@ def new_facture_pdf(request):
return render_tex(request, 'cotisations/factures.tex', {'DATE' : timezone.now(),'dest':destinataire, 'obj':objet, 'detail':detail, 'article':tbl, 'total':prix_total, 'paid':paid, 'asso_name':ASSO_NAME, 'line1':ASSO_ADDRESS_LINE1, 'line2':ASSO_ADDRESS_LINE2, 'siret':ASSO_SIRET, 'email':ASSO_EMAIL, 'phone':ASSO_PHONE})
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
+@login_required
+def facture_pdf(request, factureid):
+ try:
+ facture = Facture.objects.get(pk=factureid)
+ except Facture.DoesNotExist:
+ messages.error(request, u"Facture inexistante" )
+ return redirect("/cotisations/")
+ if not request.user.has_perms(('cableur',)) and facture.user != request.user:
+ messages.error(request, "Vous ne pouvez pas afficher une facture ne vous appartenant pas sans droit cableur")
+ return redirect("/users/profil/" + str(request.user.id))
+ vente = Vente.objects.all().filter(facture=facture)
+ ventes = []
+ for v in vente:
+ ventes.append([v, facture.number, v.prix * facture.number])
+ return render_tex(request, 'cotisations/factures.tex', {'paid':True, 'fid':facture.id, 'DATE':facture.date,'dest':facture.user, 'article':ventes, 'total': facture.prix_total(), 'asso_name':ASSO_NAME, 'line1': ASSO_ADDRESS_LINE1, 'line2':ASSO_ADDRESS_LINE2, 'siret':ASSO_SIRET, 'email':ASSO_EMAIL, 'phone':ASSO_PHONE, 'tpl_path':LOGO_PATH})
+
@permission_required('cableur')
def edit_facture(request, factureid):
try: