eo_factures: factorize invoices archiving (#61786)
This commit is contained in:
parent
da785466db
commit
04aafc724f
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import os.path
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from decimal import ROUND_HALF_UP, Decimal
|
from decimal import ROUND_HALF_UP, Decimal
|
||||||
|
|
||||||
|
@ -378,6 +379,11 @@ class Facture(models.Model):
|
||||||
def pdf(self, template_name=None, base_uri=None):
|
def pdf(self, template_name=None, base_uri=None):
|
||||||
html = HTML(string=self.html(template_name=template_name, base_uri=base_uri))
|
html = HTML(string=self.html(template_name=template_name, base_uri=base_uri))
|
||||||
pdf = html.write_pdf()
|
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
|
return pdf
|
||||||
|
|
||||||
def facturx_pdf(self, template_name=None, base_uri=None):
|
def facturx_pdf(self, template_name=None, base_uri=None):
|
||||||
|
|
|
@ -16,10 +16,8 @@
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
|
||||||
|
|
||||||
from django import http
|
from django import http
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.admin.models import LogEntry
|
from django.contrib.admin.models import LogEntry
|
||||||
from django.contrib.contenttypes.models import ContentType
|
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('/'))
|
pdf = facture.facturx_pdf(base_uri=request.build_absolute_uri('/'))
|
||||||
else:
|
else:
|
||||||
pdf = facture.pdf(base_uri=request.build_absolute_uri('/'))
|
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')
|
return http.HttpResponse(pdf, content_type='application/pdf')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue