def on_order_completed(self, sender, **kwargs): order = kwargs['order'] email = render_to_string('plata/notifications/order_completed.txt', self.context(kwargs)).splitlines() content = StringIO.StringIO() pdf = PDFDocument(content) invoice_pdf(pdf, order) message = EmailMessage( subject=email[0], body=u'\n'.join(email[2:]), to=[order.email], bcc=plata.settings.PLATA_ALWAYS_BCC + plata.settings.PLATA_ORDER_BCC, ) message.attach('invoice-%09d.pdf' % order.id, content.getvalue(), 'application/pdf') message.send() email = render_to_string('plata/notifications/packing_slip.txt', self.context(kwargs)).splitlines() content = StringIO.StringIO() pdf = PDFDocument(content) packing_slip_pdf(pdf, order) message = EmailMessage( subject='packing slip', body=u'', to=plata.settings.PLATA_SHIPPING_INFO, bcc=plata.settings.PLATA_ALWAYS_BCC + plata.settings.PLATA_ORDER_BCC, ) message.attach('packing-slip-%09d.pdf' % order.id, content.getvalue(), 'application/pdf') message.send()
def invoice_pdf(self, order): from pdfdocument.document import PDFDocument from plata.reporting.order import invoice_pdf with contextlib.closing(StringIO.StringIO()) as content: pdf = PDFDocument(content) invoice_pdf(pdf, order) return content.getvalue()
def message(self, sender, order, **kwargs): email = render_to_string('plata/notifications/order_completed.txt', self.context(kwargs)).splitlines() content = StringIO.StringIO() pdf = PDFDocument(content) invoice_pdf(pdf, order) message = EmailMessage( subject=email[0], body=u'\n'.join(email[2:]), to=[order.email], ) message.attach('invoice-%09d.pdf' % order.id, content.getvalue(), 'application/pdf') return message
def invoice_pdf(self, order): with contextlib.closing(StringIO.StringIO()) as content: pdf = PDFDocument(content) invoice_pdf(pdf, order) return content.getvalue()