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') qr_code_path = os.path.join(template_dir, 'qr-code.png')
# Use stored model fields for accuracy and consistency # 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 = { context = {
'order': order, 'order': order,
'order_number': order.pk, 'order_number': order.pk,
@@ -63,7 +67,7 @@ def generate_order_invoice(order_id):
'user': order.user, 'user': order.user,
'address': order.address, 'address': order.address,
'discount_code': order.discount_code, '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), 'total_items': sum(item.quantity for item in items),
'subtotal': order.cart_total or 0, # Stored field: total before any discounts 'subtotal': order.cart_total or 0, # Stored field: total before any discounts
'items_discount_amount': total_items_discount, 'items_discount_amount': total_items_discount,
@@ -157,6 +161,10 @@ def generate_shop_order_invoice(shop_order_id):
# Calculate subtotal (cart total before discounts) # Calculate subtotal (cart total before discounts)
subtotal = shop_order.subtotal or 0 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) # Resolve image paths for the template (absolute file paths for WeasyPrint)
import os import os
template_dir = os.path.join(settings.BASE_DIR, 'templates', 'order') 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, 'address_recipient_name': shop_order.address_recipient_name,
'items': items, 'items': items,
'items_with_discount': items_with_discount, '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, 'total_items': shop_order.items_count,
'subtotal': subtotal, # Total after product discount 'subtotal': subtotal, # Total after product discount
'items_discount_amount': total_items_discount, # Product discount amount 'items_discount_amount': total_items_discount, # Product discount amount
@@ -0,0 +1,21 @@
# Generated by Django 5.2 on 2026-05-12 05:46
import django.utils.timezone
import django_jalali.db.models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('order', '0043_shopdailyreport_is_settled_and_more'),
]
operations = [
migrations.AlterField(
model_name='ordermodel',
name='created_at',
field=django_jalali.db.models.jDateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='تاریخ ثبت سفارش'),
preserve_default=False,
),
]
@@ -0,0 +1,18 @@
# Generated by Django 5.2 on 2026-05-12 05:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('order', '0044_alter_ordermodel_created_at'),
]
operations = [
migrations.AlterField(
model_name='ordermodel',
name='created_at',
field=models.DateTimeField(auto_now_add=True, verbose_name='تاریخ ثبت سفارش'),
),
]