fix order time

This commit is contained in:
Parsa Nazer
2026-05-12 09:48:34 +03:30
parent 2f74385447
commit de77744557
3 changed files with 49 additions and 2 deletions
+10 -2
View File
@@ -55,6 +55,10 @@ def generate_order_invoice(order_id):
qr_code_path = os.path.join(template_dir, 'qr-code.png')
# Use stored model fields for accuracy and consistency
# Format the Jalali date for display
jalali_date = to_jalali(order.created_at)
created_at_jalali_str = jalali_date.strftime('%Y-%m-%d %H:%M') if jalali_date else '---'
context = {
'order': order,
'order_number': order.pk,
@@ -63,7 +67,7 @@ def generate_order_invoice(order_id):
'user': order.user,
'address': order.address,
'discount_code': order.discount_code,
'created_at_jalali': to_jalali(order.created_at),
'created_at_jalali': created_at_jalali_str,
'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,
@@ -157,6 +161,10 @@ def generate_shop_order_invoice(shop_order_id):
# Calculate subtotal (cart total before discounts)
subtotal = shop_order.subtotal or 0
# Format the Jalali date for display
jalali_date = jdatetime.datetime.fromgregorian(datetime=shop_order.order_created_at) if shop_order.order_created_at else None
created_at_jalali_str = jalali_date.strftime('%Y-%m-%d %H:%M') if jalali_date else '---'
# Resolve image paths for the template (absolute file paths for WeasyPrint)
import os
template_dir = os.path.join(settings.BASE_DIR, 'templates', 'order')
@@ -181,7 +189,7 @@ def generate_shop_order_invoice(shop_order_id):
'address_recipient_name': shop_order.address_recipient_name,
'items': items,
'items_with_discount': items_with_discount,
'created_at_jalali': jdatetime.datetime.fromgregorian(datetime=shop_order.order_created_at) if shop_order.order_created_at else None,
'created_at_jalali': created_at_jalali_str,
'total_items': shop_order.items_count,
'subtotal': subtotal, # Total after product discount
'items_discount_amount': total_items_discount, # Product discount amount