diff --git a/inventory/views.py b/inventory/views.py index 0aeac725..baf08370 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -12,6 +12,8 @@ import tempfile import numpy as np from time import sleep +from weasyprint import HTML + # from rich import print from random import randint from decimal import Decimal @@ -10971,7 +10973,27 @@ class PurchaseOrderDetailView(LoginRequiredMixin, PermissionRequiredMixin, Detai if i["po_item_status"] != "cancelled" ) return context + def get(self, request, *args, **kwargs): + self.object = self.get_object() + context = self.get_context_data(object=self.object) + + # Check if PDF format is requested + if request.GET.get('format') == 'pdf': + # Use a separate, print-friendly template for the PDF + html_string = render_to_string( + "purchase_orders/po_detail_pdf.html", + context + ) + + # Use WeasyPrint to generate the PDF + pdf = HTML(string=html_string).write_pdf() + + response = HttpResponse(pdf, content_type="application/pdf") + response["Content-Disposition"] = f'attachment; filename="PO_{self.object.po_number}.pdf"' + return response + # If not a PDF request, return the standard HTML response + return self.render_to_response(context) class PurchaseOrderListView(LoginRequiredMixin, PermissionRequiredMixin, ListView): model = PurchaseOrderModel diff --git a/templates/crm/notifications_history.html b/templates/crm/notifications_history.html index 2e7a9853..9405399a 100644 --- a/templates/crm/notifications_history.html +++ b/templates/crm/notifications_history.html @@ -73,7 +73,7 @@ body { {% endif %}
-
+
{{ notification.message|safe }}

@@ -100,7 +100,7 @@ body {

-
+

{% trans "Status" %}