verify invoice emails gets added to the queue and fix names

This commit is contained in:
Stephan Telling 2017-05-21 20:43:05 +02:00
parent dbff6a3f00
commit 46cf9c53f7
No known key found for this signature in database
GPG key ID: D4892289F36ADA9B
2 changed files with 19 additions and 11 deletions

View file

@ -3,7 +3,7 @@ import logging
logger = logging.getLogger("bornhack.%s" % __name__) logger = logging.getLogger("bornhack.%s" % __name__)
def send_creditnote_email(creditnote): def add_creditnote_email(creditnote):
# put formatdict together # put formatdict together
formatdict = { formatdict = {
'creditnote': creditnote, 'creditnote': creditnote,
@ -23,7 +23,7 @@ def send_creditnote_email(creditnote):
) )
def send_invoice_email(invoice): def add_invoice_email(invoice):
# put formatdict together # put formatdict together
formatdict = { formatdict = {
'ordernumber': invoice.order.pk, 'ordernumber': invoice.order.pk,
@ -45,7 +45,7 @@ def send_invoice_email(invoice):
) )
def send_test_email(recipient): def add_test_email(recipient):
return add_outgoing_email( return add_outgoing_email(
text_template='emails/testmail.txt', text_template='emails/testmail.txt',
to_recipients=recipient, to_recipients=recipient,

View file

@ -1,6 +1,6 @@
from django.core.files import File from django.core.files import File
from shop.pdf import generate_pdf_letter from shop.pdf import generate_pdf_letter
from shop.email import send_invoice_email, send_creditnote_email from shop.email import add_invoice_email, add_creditnote_email
from shop.models import Order, CustomOrder, Invoice, CreditNote from shop.models import Order, CustomOrder, Invoice, CreditNote
import logging import logging
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
@ -54,10 +54,18 @@ def do_work():
for invoice in Invoice.objects.filter(order__isnull=False, sent_to_customer=False).exclude(pdf=''): for invoice in Invoice.objects.filter(order__isnull=False, sent_to_customer=False).exclude(pdf=''):
logger.info("found unmailed Invoice object: %s" % invoice) logger.info("found unmailed Invoice object: %s" % invoice)
# add email to the outgoing email queue # add email to the outgoing email queue
send_invoice_email(invoice=invoice) if add_invoice_email(invoice=invoice):
invoice.sent_to_customer = True invoice.sent_to_customer = True
invoice.save() invoice.save()
logger.info('OK: Invoice email added to queue.') logger.info('OK: Invoice email to {} added to queue.'.format(
invoice.order.user.email)
)
else:
logger.error('Unable to add email for invoice {} to {}'.format(
invoice.pk,
invoice.order.user.email
)
)
# check if we need to generate any pdf creditnotes? # check if we need to generate any pdf creditnotes?
for creditnote in CreditNote.objects.filter(pdf=''): for creditnote in CreditNote.objects.filter(pdf=''):
@ -82,10 +90,10 @@ def do_work():
# check if we need to send out any creditnotes (only where pdf has been generated) # check if we need to send out any creditnotes (only where pdf has been generated)
for creditnote in CreditNote.objects.filter(sent_to_customer=False).exclude(pdf=''): for creditnote in CreditNote.objects.filter(sent_to_customer=False).exclude(pdf=''):
# send the email # send the email
if send_creditnote_email(creditnote=creditnote): if add_creditnote_email(creditnote=creditnote):
logger.info('OK: Creditnote email sent to %s' % creditnote.user.email) logger.info('OK: Creditnote email to %s added' % creditnote.user.email)
creditnote.sent_to_customer = True creditnote.sent_to_customer = True
creditnote.save() creditnote.save()
else: else:
logger.error('Unable to send creditnote email for creditnote %s to %s' % (creditnote.pk, creditnote.user.email)) logger.error('Unable to add creditnote email for creditnote %s to %s' % (creditnote.pk, creditnote.user.email))