|
|
|
@ -2,11 +2,11 @@ from django.shortcuts import render, get_object_or_404
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
from datetime import timedelta
|
|
|
|
|
from .models import *
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
from django.http import JsonResponse, HttpResponse
|
|
|
|
|
from django.template.loader import get_template
|
|
|
|
|
from weasyprint import HTML
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# LISTING
|
|
|
|
|
def items (request, *args, **kwargs):
|
|
|
|
|
context = {
|
|
|
|
@ -114,14 +114,11 @@ def invoice_details (request, invoice_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_pdf(request):
|
|
|
|
|
# Render the template
|
|
|
|
|
template = get_template('invoice.html')
|
|
|
|
|
html = template.render()
|
|
|
|
|
|
|
|
|
|
# Create a PDF file
|
|
|
|
|
pdf_file = HTML(string=html).write_pdf()
|
|
|
|
|
|
|
|
|
|
# Prepare HTTP response
|
|
|
|
|
response = HttpResponse(pdf_file, content_type='application/pdf')
|
|
|
|
|
response['Content-Disposition'] = 'filename="invoice.pdf"'
|
|
|
|
|
return response
|
|
|
|
|
template = get_template('invoice-details.html')
|
|
|
|
|
context = {}
|
|
|
|
|
html_string = template.render(context)
|
|
|
|
|
|
|
|
|
|
pdf = HTML(string=html_string).write_pdf()
|
|
|
|
|
response = HttpResponse(pdf, content_type='application/pdf')
|
|
|
|
|
response['Content-Disposition'] = 'attachment; filename="my_pdf.pdf"'
|
|
|
|
|
return response
|