diff --git a/eo_gestion/eo_facture/models.py b/eo_gestion/eo_facture/models.py index 6c8c70a..eae2c00 100644 --- a/eo_gestion/eo_facture/models.py +++ b/eo_gestion/eo_facture/models.py @@ -28,6 +28,7 @@ from django.db.models import F, Q, Sum from django.db.models.query import QuerySet from django.db.models.signals import post_delete, post_save from django.template.loader import get_template +from django.utils.encoding import force_text from django.utils.timezone import now from django.utils.translation import ugettext_lazy as _ from weasyprint import HTML @@ -428,6 +429,13 @@ class Facture(models.Model): payment.save() return facture_avoir + def filename(self, add_client_name=False): + return '%s%s%s.pdf' % ( + self.code(), + '-%s' % force_text(self.contrat.client.nom) if add_client_name else '', + '-AVOIR' if self.annulation else '', + ) + class Meta: ordering = ("-id",) diff --git a/eo_gestion/eo_facture/templates/admin/eo_facture/facture/change_form.html b/eo_gestion/eo_facture/templates/admin/eo_facture/facture/change_form.html index 883b330..b6063d0 100644 --- a/eo_gestion/eo_facture/templates/admin/eo_facture/facture/change_form.html +++ b/eo_gestion/eo_facture/templates/admin/eo_facture/facture/change_form.html @@ -10,7 +10,7 @@ {% if original.contrat %}
  • Contrat
  • {% endif %} -
  • Imprimer
  • +
  • Imprimer
  • {% if original.client.chorus_structure and not original.proforma %}
  • Envoyer à Chorus
  • {% endif %} diff --git a/eo_gestion/eo_facture/views.py b/eo_gestion/eo_facture/views.py index a4ad029..e2de8d0 100644 --- a/eo_gestion/eo_facture/views.py +++ b/eo_gestion/eo_facture/views.py @@ -24,7 +24,6 @@ from django.contrib import messages from django.contrib.admin.models import LogEntry from django.contrib.contenttypes.models import ContentType from django.shortcuts import get_object_or_404, redirect -from django.utils.encoding import force_text from eo_gestion.chorus.chorus import push_to_chorus @@ -46,15 +45,7 @@ def facture_pdf(request, facture_id): else: pdf = facture.pdf(base_uri=request.build_absolute_uri('/')) if hasattr(settings, 'FACTURE_DIR'): - filename = os.path.join( - settings.FACTURE_DIR, - '%s-%s%s.pdf' - % ( - facture.code(), - force_text(facture.contrat.client.nom), - '-AVOIR' if facture.annulation else '', - ), - ) + filename = os.path.join(settings.FACTURE_DIR, facture.filename(add_client_name=True)) with open(filename, 'wb') as fd: fd.write(pdf) return http.HttpResponse(pdf, content_type='application/pdf')