po download added
This commit is contained in:
parent
543b896db2
commit
f5856d6fb7
@ -12,6 +12,8 @@ import tempfile
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
from weasyprint import HTML
|
||||||
|
|
||||||
# from rich import print
|
# from rich import print
|
||||||
from random import randint
|
from random import randint
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
@ -10971,7 +10973,27 @@ class PurchaseOrderDetailView(LoginRequiredMixin, PermissionRequiredMixin, Detai
|
|||||||
if i["po_item_status"] != "cancelled"
|
if i["po_item_status"] != "cancelled"
|
||||||
)
|
)
|
||||||
return context
|
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):
|
class PurchaseOrderListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
|
||||||
model = PurchaseOrderModel
|
model = PurchaseOrderModel
|
||||||
|
|||||||
@ -73,7 +73,7 @@ body {
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="flex-grow-1">
|
<div class="flex-grow-1">
|
||||||
<h5 class="mb-1 text-dark fw-normal">
|
<h5 class="mb-1 fw-normal">
|
||||||
{{ notification.message|safe }}
|
{{ notification.message|safe }}
|
||||||
</h5>
|
</h5>
|
||||||
<p class="text-muted fs-6 mb-0 mt-2">
|
<p class="text-muted fs-6 mb-0 mt-2">
|
||||||
@ -100,7 +100,7 @@ body {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-4 d-none d-lg-block">
|
<div class="col-lg-4 d-none d-lg-block">
|
||||||
<div class="card border-0 rounded-4 p-4 sticky-top mt-3 bg-gray-200">
|
<div class="card border-0 rounded-4 p-4 sticky-top position-static mt-3 bg-gray-200 w-100">
|
||||||
<h4 class="fw-bold mb-3">{% trans "Status" %}</h4>
|
<h4 class="fw-bold mb-3">{% trans "Status" %}</h4>
|
||||||
<ul class="list-unstyled mb-0">
|
<ul class="list-unstyled mb-0">
|
||||||
<li class="d-flex align-items-center mb-2">
|
<li class="d-flex align-items-center mb-2">
|
||||||
|
|||||||
@ -9,10 +9,9 @@
|
|||||||
<main class="py-5">
|
<main class="py-5">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% if groups or request.GET.q %}
|
{% if groups or request.GET.q %}
|
||||||
<div class="card border-0 rounded-4 animate__animated animate__fadeInUp">
|
<div class=" d-flex flex-column flex-md-row justify-content-between align-items-md-center p-4">
|
||||||
<div class="card-header border-bottom d-flex flex-column flex-md-row justify-content-between align-items-md-center p-4">
|
|
||||||
<h5 class="card-title mb-2 mb-md-0 me-md-4 fw-bold">
|
<h5 class="card-title mb-2 mb-md-0 me-md-4 fw-bold">
|
||||||
<i class="fa-solid fa-user-group fs-3 me-1 text-primary "></i>{% trans "Groups" %}
|
<i class="fa-solid fa-user-group fs-3 me-1 "></i>{% trans "Groups" %}
|
||||||
</h5>
|
</h5>
|
||||||
<div class="d-flex gap-2">
|
<div class="d-flex gap-2">
|
||||||
<a href="{% url 'group_create' request.dealer.slug %}"
|
<a href="{% url 'group_create' request.dealer.slug %}"
|
||||||
@ -26,16 +25,18 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card border-0 rounded-4 animate__animated animate__fadeInUp">
|
||||||
|
|
||||||
<div class="card-body p-0">
|
<div class="card-body p-0">
|
||||||
<div class="table-responsive scrollbar mx-n1 px-1 mt-3">
|
<div class="table-responsive scrollbar mx-n1 px-1 mt-3">
|
||||||
<table class="table align-items-center table-hover mb-0">
|
<table class="table align-items-center table-hover mb-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="bg-light">
|
<tr class="">
|
||||||
<th scope="col" class="text-secondary text-uppercase fw-bold ps-4">{% trans 'name'|capfirst %}</th>
|
<th scope="col" class=" text-uppercase fw-bold ps-4">{% trans 'name'|capfirst %}</th>
|
||||||
<th scope="col" class="text-secondary text-uppercase fw-bold">{% trans 'total Users'|capfirst %}</th>
|
<th scope="col" class="text-uppercase fw-bold">{% trans 'total Users'|capfirst %}</th>
|
||||||
<th scope="col" class="text-secondary text-uppercase fw-bold">{% trans 'total permission'|capfirst %}</th>
|
<th scope="col" class="text-uppercase fw-bold">{% trans 'total permission'|capfirst %}</th>
|
||||||
<th scope="col"
|
<th scope="col"
|
||||||
class="text-secondary text-uppercase fw-bold text-end pe-4">
|
class="text-uppercase fw-bold text-end pe-4">
|
||||||
{% trans 'actions'|capfirst %}
|
{% trans 'actions'|capfirst %}
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -8,8 +8,7 @@
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
hx-post="{% url 'update_schedule' request.dealer.slug task.pk %}"
|
hx-post="{% url 'update_schedule' request.dealer.slug task.pk %}"
|
||||||
hx-trigger="change"
|
hx-trigger="change"
|
||||||
hx-swap="none"
|
hx-swap="outerHTML"
|
||||||
hx-on:click="$(this).closest('tr').toggleClass('completed-task')"
|
|
||||||
hx-target="#task-{{ task.pk }}" />
|
hx-target="#task-{{ task.pk }}" />
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@ -34,8 +34,8 @@
|
|||||||
</script>
|
</script>
|
||||||
{% if not create_po %}
|
{% if not create_po %}
|
||||||
{% if style == 'po-detail' %}
|
{% if style == 'po-detail' %}
|
||||||
<div class="card shadow-sm border-0 mb-2">
|
<div class="card mb-2">
|
||||||
<div class="card-header bg-light ">
|
<div class="card-header">
|
||||||
<div class="d-flex align-items-center mb-2 ">
|
<div class="d-flex align-items-center mb-2 ">
|
||||||
<span class="me-3 text-primary">{% icon 'uil:bill' 36 %}</span>
|
<span class="me-3 text-primary">{% icon 'uil:bill' 36 %}</span>
|
||||||
<h2 class="h3 mb-0 text-primary me-4">{{ po_model.po_number }}</h2>
|
<h2 class="h3 mb-0 text-primary me-4">{{ po_model.po_number }}</h2>
|
||||||
@ -94,7 +94,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer bg-light" hx-boost="false">
|
<div class="card-footer" hx-boost="false">
|
||||||
{% if perms.django_ledger.change_purchaseordermodel %}
|
{% if perms.django_ledger.change_purchaseordermodel %}
|
||||||
<div class="d-flex flex-wrap gap-2 justify-content-between">
|
<div class="d-flex flex-wrap gap-2 justify-content-between">
|
||||||
<a href="{% url 'purchase_order_update' dealer_slug=request.dealer.slug entity_slug=entity_slug po_pk=po_model.pk %}"
|
<a href="{% url 'purchase_order_update' dealer_slug=request.dealer.slug entity_slug=entity_slug po_pk=po_model.pk %}"
|
||||||
|
|||||||
@ -15,6 +15,10 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{% include 'purchase_orders/includes/card_po.html' with dealer_slug=request.dealer.slug po_model=po_model entity_slug=entity_slug style='po-detail' %}
|
{% include 'purchase_orders/includes/card_po.html' with dealer_slug=request.dealer.slug po_model=po_model entity_slug=entity_slug style='po-detail' %}
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<a class="btn btn-phoenix-primary w-100 my-2"
|
||||||
|
href="{{ request.path }}?format=pdf"><i class="fa-solid fa-arrow-down me-1"></i>{% trans 'Download PDF' %}</a>
|
||||||
|
</di>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
|
|||||||
178
templates/purchase_orders/po_detail_pdf.html
Normal file
178
templates/purchase_orders/po_detail_pdf.html
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% load static %}
|
||||||
|
{% load django_ledger %}
|
||||||
|
{% load tenhal_tag %}
|
||||||
|
{% load custom_filters %}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{{ po_model.po_number }}</title>
|
||||||
|
<style>
|
||||||
|
/* General Body and Font Styles */
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #333;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Page Layout and Margins for PDF */
|
||||||
|
@page {
|
||||||
|
size: A4;
|
||||||
|
margin: 20mm;
|
||||||
|
@top-right {
|
||||||
|
content: "Page " counter(page) " of " counter(pages);
|
||||||
|
font-size: 10px;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Header Styles */
|
||||||
|
.document-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
border-bottom: 2px solid #333;
|
||||||
|
padding-bottom: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.document-header .logo {
|
||||||
|
max-width: 150px;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
.document-header h1 {
|
||||||
|
font-size: 24px;
|
||||||
|
margin: 0;
|
||||||
|
color: #0056b3; /* A professional blue */
|
||||||
|
}
|
||||||
|
.document-header address {
|
||||||
|
text-align: right;
|
||||||
|
font-style: normal;
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Document Details Section */
|
||||||
|
.document-details {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.document-details .section {
|
||||||
|
width: 48%;
|
||||||
|
}
|
||||||
|
.document-details h2 {
|
||||||
|
font-size: 14px;
|
||||||
|
border-bottom: 1px solid #ccc;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
.document-details p {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.document-details .label {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Table Styles */
|
||||||
|
.table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
.table th, .table td {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 8px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.table th {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.table tfoot td {
|
||||||
|
border-top: 2px solid #333;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.text-right {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Footer Styles */
|
||||||
|
.document-footer {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 10px;
|
||||||
|
color: #888;
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
padding-top: 15px;
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="document-header">
|
||||||
|
<div>
|
||||||
|
{% if request.dealer.logo %}
|
||||||
|
<img src="{{ request.dealer.logo.url }}" alt="Company Logo" class="logo">
|
||||||
|
{% else %}
|
||||||
|
<h1>{{ request.dealer.name }}</h1>
|
||||||
|
{% endif %}
|
||||||
|
<address>
|
||||||
|
{{ request.dealer.entity.address.street }}<br>
|
||||||
|
{{ request.dealer.entity.address.city }}, {{ request.dealer.entity.address.state }} {{ request.dealer.entity.address.zip_code }}<br>
|
||||||
|
Email: {{ request.dealer.user.email }}<br>
|
||||||
|
Phone: {{ request.dealer.phone }}
|
||||||
|
</address>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h1>PURCHASE ORDER</h1>
|
||||||
|
<h2 style="font-size: 18px;">{{ po_model.po_number }}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="document-details">
|
||||||
|
<div class="section">
|
||||||
|
<h2>BILL TO:</h2>
|
||||||
|
<p><span class="label">Vendor:</span> </p>
|
||||||
|
<p><span class="label">Email:</span> </p>
|
||||||
|
<p><span class="label">Phone:</span> </p>
|
||||||
|
<p><span class="label">Address:</span> </p>
|
||||||
|
<p>{{ po_model.vendor_model.address.city|default:"" }}, {{ po_model.vendor_model.address.state|default:"" }} {{ po_model.vendor_model.address.zip_code|default:"" }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="section">
|
||||||
|
<h2>DETAILS:</h2>
|
||||||
|
<p><span class="label">PO Number:</span> {{ po_model.po_number }}</p>
|
||||||
|
<p><span class="label">Issue Date:</span> {{ po_model.date_created|date:"F j, Y" }}</p>
|
||||||
|
<p><span class="label">Status:</span> {{ po_model.get_po_status_display }}</p>
|
||||||
|
<p><span class="label">Due Date:</span> {{ po_model.due_date|date:"F j, Y"|default:"N/A" }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<div class="table-responsive">
|
||||||
|
{% po_item_table1 po_items %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="document-details" style="margin-top: 30px;">
|
||||||
|
<div class="section">
|
||||||
|
<h2>NOTES:</h2>
|
||||||
|
<p>{{ po_model.notes|default:"No additional notes." }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="section text-right">
|
||||||
|
<p class="h4"><span class="label">Total Amount:</span> {{ po_total_amount|currency_format }}<span class="icon-saudi_riyal"></span></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="document-footer">
|
||||||
|
<p>© {% now "Y" %} {{ request.dealer.name }}. All rights reserved.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -9,7 +9,7 @@
|
|||||||
{% if users or request.GET.q %}
|
{% if users or request.GET.q %}
|
||||||
<div class="d-flex align-items-center justify-content-between mb-4">
|
<div class="d-flex align-items-center justify-content-between mb-4">
|
||||||
<h1 class="h3 mb-0 text-muted d-flex align-items-center">
|
<h1 class="h3 mb-0 text-muted d-flex align-items-center">
|
||||||
<i class="fa-solid fa-user-tie text-primary me-3 fs-2"></i>
|
<i class="fa-solid fa-user-tie me-3 fs-2"></i>
|
||||||
{% trans "Staffs" %}
|
{% trans "Staffs" %}
|
||||||
</h1>
|
</h1>
|
||||||
{% if request.user.userplan %}
|
{% if request.user.userplan %}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user