Example #1
0
def generarFactura(request):
    
    try:
        nroNota = request.GET.get("nroNota")
        notaVenta = NotaVenta.objects.get(pk = nroNota)
        af = AdaptadorFactura()
        af.inicializar(notaVenta)

        print "path = " + TEMPLATE_DIRS+'/facturaBase.odt'
        af.inicializar(notaVenta)
        repos = relatorio.ReportRepository()
        basic = Template(source="", filepath=TEMPLATE_DIRS+'/facturaBase.odt')

        file(TEMPLATE_DIRS+'/factura.odt', 'wb').write(basic.generate(factura=af, detalles=af.detalles).render().getvalue())        
        os.system('unoconv -f pdf '+TEMPLATE_DIRS+'/factura.odt')
        with open(TEMPLATE_DIRS+'/factura.pdf', 'r') as pdf:
            response = HttpResponse(pdf.read(), mimetype='application/pdf')
            response['Content-Disposition'] = 'inline;filename=some_file.pdf'
            pdf.close()
            return response

    except ObjectDoesNotExist:
        raise ErrorCobro()