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:
2025-12-18 16:23:35 +01:00
parent 1751badb90
commit 72155d4560
21 changed files with 69 additions and 44 deletions

View File

@@ -1,4 +1,4 @@
# Generated by Django 5.2.9 on 2025-12-14 02:23
# Generated by Django 5.2.7 on 2025-12-18 15:11
import django.core.validators
import django.db.models.deletion

View File

@@ -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

View File

@@ -5,6 +5,10 @@ from django.apps import apps
from django.utils import timezone
# -- CLEANUP TASKS --
# Delete expired/cancelled orders (older than 24 hours)
@shared_task
def delete_expired_orders():
Order = apps.get_model('commerce', 'Order')