diff --git a/backend/order/invoice_generator.py b/backend/order/invoice_generator.py index 55b67bd..404c57d 100644 --- a/backend/order/invoice_generator.py +++ b/backend/order/invoice_generator.py @@ -6,6 +6,7 @@ These functions generate PDF invoices from HTML templates. from io import BytesIO from datetime import datetime from django.template.loader import render_to_string +from backend.utils.jalali_formatter import to_jalali from weasyprint import HTML from django.conf import settings import jdatetime @@ -62,7 +63,7 @@ def generate_order_invoice(order_id): 'user': order.user, 'address': order.address, 'discount_code': order.discount_code, - 'created_at_jalali': jdatetime.datetime.fromgregorian(datetime=order.created_at) if order.created_at else None, + 'created_at_jalali': to_jalali(order.created_at), 'total_items': sum(item.quantity for item in items), 'subtotal': order.cart_total or 0, # Stored field: total before any discounts 'items_discount_amount': total_items_discount, diff --git a/backend/templates/order/invoice_order2.html b/backend/templates/order/invoice_order2.html index 243f4f9..913dc50 100644 --- a/backend/templates/order/invoice_order2.html +++ b/backend/templates/order/invoice_order2.html @@ -1,4 +1,3 @@ - {% load price_filters %} diff --git a/backend/utils/jalali_formatter.py b/backend/utils/jalali_formatter.py new file mode 100644 index 0000000..1282874 --- /dev/null +++ b/backend/utils/jalali_formatter.py @@ -0,0 +1,17 @@ +import jdatetime +from django.utils import timezone + +def to_jalali(dt): + if not dt: + return None + + dt = timezone.localtime(dt) + + return jdatetime.datetime.fromgregorian( + year=dt.year, + month=dt.month, + day=dt.day, + hour=dt.hour, + minute=dt.minute, + second=dt.second, + )