Hi I am trying to set up invoice generation for django oscar. I have found a useful link https://groups.google.com/forum/#!topic/django-oscar/sg1qtyuu32Q (two main links from this google groups are https://gist.github.com/elbaschid/8722203 and https://gist.github.com/elbaschid/8776935)
but I am having an issue trying to set this up.
I saved my templates as suggested in the link and the below is the code under OrderListView:
def generate_packing_slips(self, request, orders):
template = loader.get_template(self.packing_slip_template)
main_pdf = pisaPDF()
for order in orders:
voucher_codes = []
for discount in order.discounts.all():
if discount.voucher_code:
voucher_codes.append(discount.voucher_code)
context = RequestContext(request, {
'order': order,
'STATIC_ROOT': settings.STATIC_ROOT,
'voucher_codes': voucher_codes,
})
html = template.render(context)
result = StringIO()
order_pdf = pisa.pisaDocument(StringIO(html.encode("UTF-8")), result)
if order_pdf.err:
messages.error(
self.request,
_("An problem occured trying to generate the packing slip for "
"order #%s") % order.number,
)
else:
main_pdf.addDocument(order_pdf)
response = HttpResponse(main_pdf.getvalue(), mimetype='application/pdf')
filename = self.get_packing_slip_filename(orders)
response['Content-Disposition'] = 'attachment; filename=%s' % filename
return response
However this gives me an error of
AttributeError at /dashboard/orders/
'OrderListView' object has no attribute 'packing_slip_template'
The path for the template is 'dashboard/orders/order_packing_slip.html'
I also added a button on order_list.html by adding the below code:
<button style="margin-right:10px" type="submit" class="btn w3-black w3-hover-dark-gray" name="action" value="generate_packing_slips" data-loading-text="{% trans 'Submitting...' %}">{% trans "Download" %}</button>
I would be grateful if you have any suggestions for the solutions!
Many Thanks