fix order time
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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='تاریخ ثبت سفارش'),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user