eo_facture: do not depend upon self.contrat for filename (#65103)
self.client is required but not self.contrat.
This commit is contained in:
parent
734ef5bf06
commit
26d0be2441
|
@ -29,7 +29,6 @@ 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
|
||||
|
@ -381,7 +380,7 @@ class Facture(models.Model):
|
|||
pdf = html.write_pdf()
|
||||
|
||||
if hasattr(settings, 'FACTURE_DIR'):
|
||||
filename = os.path.join(settings.FACTURE_DIR, self.filename(add_client_name=True))
|
||||
filename = os.path.join(settings.FACTURE_DIR, self.filename_with_client())
|
||||
with open(filename, 'wb') as fd:
|
||||
fd.write(pdf)
|
||||
return pdf
|
||||
|
@ -435,12 +434,15 @@ 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 '',
|
||||
)
|
||||
def filename(self):
|
||||
avoir = '-AVOIR' if self.annulation else ''
|
||||
filename = f'{self.code()}{avoir}.pdf'
|
||||
return filename
|
||||
|
||||
def filename_with_client(self):
|
||||
avoir = '-AVOIR' if self.annulation else ''
|
||||
filename = f'{self.code()}-{self.client.nom}{avoir}.pdf'
|
||||
return filename
|
||||
|
||||
class Meta:
|
||||
ordering = ("-id",)
|
||||
|
|
Loading…
Reference in New Issue