Refactor Zasilkovna client, update imports and cleanup
Refactored the Zasilkovna SOAP client to use a singleton pattern with caching and lazy loading, improving reliability and startup performance. Updated invoice PDF generation to import WeasyPrint lazily, preventing startup failures on systems missing dependencies. Cleaned up unused imports and code in several frontend components, removed unused state and variables, and adjusted Docker frontend port mapping. Also updated Django migration files to reflect a new generation timestamp.
This commit is contained in:
@@ -7,9 +7,9 @@ from django.template.loader import render_to_string
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
|
||||
from weasyprint import HTML
|
||||
import os
|
||||
|
||||
|
||||
from configuration.models import SiteConfiguration
|
||||
|
||||
from thirdparty.zasilkovna.models import ZasilkovnaPacket
|
||||
@@ -582,6 +582,16 @@ class Invoice(models.Model):
|
||||
order = Order.objects.get(invoice=self)
|
||||
# Render HTML
|
||||
html_string = render_to_string("invoice/invoice.html", {"invoice": self})
|
||||
# Import WeasyPrint lazily to avoid startup failures when system
|
||||
# libraries (Pango/GObject) are not present on Windows.
|
||||
try:
|
||||
|
||||
from weasyprint import HTML
|
||||
except Exception as e:
|
||||
raise RuntimeError(
|
||||
"WeasyPrint is not available. Install its system dependencies (Pango/GTK) or run the backend in Docker."
|
||||
) from e
|
||||
|
||||
pdf_bytes = HTML(string=html_string).write_pdf()
|
||||
|
||||
# Save directly to FileField
|
||||
|
||||
Reference in New Issue
Block a user