From 04aafc724faa9547445d43c0b7b4913e5b524e5f Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Thu, 17 Feb 2022 12:33:23 +0100 Subject: [PATCH] eo_factures: factorize invoices archiving (#61786) --- eo_gestion/eo_facture/models.py | 6 ++++++ eo_gestion/eo_facture/views.py | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eo_gestion/eo_facture/models.py b/eo_gestion/eo_facture/models.py index eae2c00..5353efe 100644 --- a/eo_gestion/eo_facture/models.py +++ b/eo_gestion/eo_facture/models.py @@ -16,6 +16,7 @@ import datetime +import os.path from collections import defaultdict from decimal import ROUND_HALF_UP, Decimal @@ -378,6 +379,11 @@ class Facture(models.Model): def pdf(self, template_name=None, base_uri=None): html = HTML(string=self.html(template_name=template_name, base_uri=base_uri)) pdf = html.write_pdf() + + if hasattr(settings, 'FACTURE_DIR'): + filename = os.path.join(settings.FACTURE_DIR, self.filename(add_client_name=True)) + with open(filename, 'wb') as fd: + fd.write(pdf) return pdf def facturx_pdf(self, template_name=None, base_uri=None): diff --git a/eo_gestion/eo_facture/views.py b/eo_gestion/eo_facture/views.py index e2de8d0..3126039 100644 --- a/eo_gestion/eo_facture/views.py +++ b/eo_gestion/eo_facture/views.py @@ -16,10 +16,8 @@ import logging -import os.path from django import http -from django.conf import settings from django.contrib import messages from django.contrib.admin.models import LogEntry from django.contrib.contenttypes.models import ContentType @@ -44,10 +42,6 @@ def facture_pdf(request, facture_id): pdf = facture.facturx_pdf(base_uri=request.build_absolute_uri('/')) else: pdf = facture.pdf(base_uri=request.build_absolute_uri('/')) - if hasattr(settings, 'FACTURE_DIR'): - 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')