Commit 61733e99 authored by Dalahro's avatar Dalahro

Facture pdf depuis une facture

parent 26f5965a
......@@ -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
......
......@@ -8,6 +8,7 @@
<th>Moyen de paiement</th>
<th>Date</th>
<th></th>
<th></th>
</tr>
</thead>
{% for facture in facture_list %}
......@@ -19,6 +20,7 @@
<td>{{ facture.paiement }}</td>
<td>{{ facture.date }}</td>
<td>{% if is_cableur %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-facture' facture.id %}"><i class="glyphicon glyphicon-bitcoin"></i> Editer</a>{% endif %}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:facture-pdf' facture.id %}"><i class="glyphicon glyphicon-save"></i> PDF</a></td>
</tr>
{% endfor %}
</table>
......
......@@ -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 %}
......
......@@ -5,6 +5,7 @@ from . import views
urlpatterns = [
url(r'^new_facture/(?P<userid>[0-9]+)$', views.new_facture, name='new-facture'),
url(r'^edit_facture/(?P<factureid>[0-9]+)$', views.edit_facture, name='edit-facture'),
url(r'^facture_pdf/(?P<factureid>[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<articleid>[0-9]+)$', views.edit_article, name='edit-article'),
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment