a few more fixes for the new invoice generation

This commit is contained in:
Thomas Steen Rasmussen 2016-05-30 20:30:52 +02:00
parent 23b1b5e350
commit 0b4426b3d3
2 changed files with 5 additions and 8 deletions

View file

@ -40,7 +40,7 @@ def send_email(emailtype, recipient, formatdict, subject, sender='BornHack <nore
return True
def send_invoice_email(invoice, attachment):
def send_invoice_email(invoice):
# put formatdict together
formatdict = {
'ordernumber': invoice.order.pk,
@ -57,6 +57,7 @@ def send_invoice_email(invoice, attachment):
formatdict=formatdict,
subject=subject,
sender='noreply@bornfiber.dk',
attachment=invoice.pdf,
)

View file

@ -20,7 +20,7 @@ class Command(BaseCommand):
self.stdout.write('Generated Invoice object for order %s' % order)
### check if we need to generate any pdf invoices
for invoice in Invoice.objects.filter(pdf_generated=False):
for invoice in Invoice.objects.filter(pdf__isnull=True):
# put the dict with data for the pdf together
formatdict = {
'invoice': invoice,
@ -48,13 +48,9 @@ class Command(BaseCommand):
invoice.save()
### check if we need to send out any invoices
for invoice in Invoice.objects.filter(sent_to_customer=False, pdf_generated=True):
# read the pdf invoice from the archive
with open(settings.INVOICE_ARCHIVE_PATH+invoice.filename, 'r') as fh:
pdffile = fh.read()
for invoice in Invoice.objects.filter(sent_to_customer=False, pdf__isnull=False):
# send the email
if send_invoice_email(invoice=invoice, attachment=pdffile):
if send_invoice_email(invoice=invoice):
self.stdout.write('OK: Invoice email sent to %s' % order.user.email)
invoice.sent_to_customer=True
invoice.save()