From f5856d6fb79ced5b5cbca6aa128afaa8b6f4e808 Mon Sep 17 00:00:00 2001 From: Faheed Date: Tue, 16 Sep 2025 17:05:29 +0300 Subject: [PATCH] po download added --- inventory/views.py | 22 +++ templates/crm/notifications_history.html | 4 +- templates/groups/group_list.html | 17 +- templates/partials/task.html | 5 +- .../purchase_orders/includes/card_po.html | 6 +- templates/purchase_orders/po_detail.html | 4 + templates/purchase_orders/po_detail_pdf.html | 178 ++++++++++++++++++ templates/users/user_list.html | 2 +- 8 files changed, 221 insertions(+), 17 deletions(-) create mode 100644 templates/purchase_orders/po_detail_pdf.html 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" %}