From a8d3c7f1080ae85afab05595e2a24a5bd7be39f1 Mon Sep 17 00:00:00 2001 From: Martin Quarda Date: Wed, 2 Oct 2024 18:48:04 +0200 Subject: [PATCH] new invoices --- alkatorapi/templates/invoice.html | 253 ------------------------------ alkatorapi/views.py | 2 +- get_invoices.py | 29 ++++ 3 files changed, 30 insertions(+), 254 deletions(-) create mode 100644 get_invoices.py diff --git a/alkatorapi/templates/invoice.html b/alkatorapi/templates/invoice.html index b963df9..fb6808e 100644 --- a/alkatorapi/templates/invoice.html +++ b/alkatorapi/templates/invoice.html @@ -265,105 +265,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -395,162 +296,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - V obchodním rejstříku je zapsána pod spisovou značkou C 52475, Krajský soud v Hradci Králové. - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/alkatorapi/views.py b/alkatorapi/views.py index 394e36f..c0fc161 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -200,7 +200,7 @@ def photos(request): def invoice(request): user = User.objects.get(invoice_id=request.GET['invoice_id']) return TemplateResponse( - request, + None, 'invoice.html', { 'user': user, diff --git a/get_invoices.py b/get_invoices.py new file mode 100644 index 0000000..915ac96 --- /dev/null +++ b/get_invoices.py @@ -0,0 +1,29 @@ +from datetime import date, datetime, timedelta +from django.template.response import TemplateResponse +from alkatorapi.models import User +from xhtml2pdf import pisa +from weasyprint import HTML +from pypdf import PdfWriter +import asyncio + +def html_to_pdf(html_content, output_path): + HTML(string=html_content).write_pdf(output_path) + +merger = PdfWriter() + +for user in User.objects.all().order_by('last_name', 'first_name'): + template = TemplateResponse( + None, + 'invoice.html', + { + 'user': user, + 'paid_date': user.register_date + timedelta(days=1), + } + ) + template.render() + pdf_name = f"{user.last_name}_{user.first_name}.pdf" + html_to_pdf(template.content, pdf_name) + merger.append(pdf_name) + +merger.write('result.pdf') +merger.close() \ No newline at end of file