new invoice design

This commit is contained in:
Parsa Nazer
2026-02-24 16:51:15 +03:30
parent a40b371b27
commit ad80907aa4
5 changed files with 892 additions and 161 deletions
+26 -6
View File
@@ -46,6 +46,13 @@ def generate_order_invoice(order_id):
'final_price': item.price_after_special_discount(),
})
# Resolve image paths for the template (absolute file paths for WeasyPrint)
import os
template_dir = os.path.join(settings.BASE_DIR, 'templates', 'order')
logo_path = os.path.join(template_dir, 'logo2.png')
logo_pattern_path = os.path.join(template_dir, 'logo-pattern.png')
qr_code_path = os.path.join(template_dir, 'qr-code.png')
# Use stored model fields for accuracy and consistency
context = {
'order': order,
@@ -66,13 +73,16 @@ def generate_order_invoice(order_id):
'final_price': order.final_price or 0, # Stored field: final price after all calculations
'is_paid': order.is_paid,
'status': order.get_status_display(),
'logo_path': logo_path,
'logo_pattern_path': logo_pattern_path,
'qr_code_path': qr_code_path,
}
# Render HTML template
html_string = render_to_string('order/invoice_order.html', context)
html_string = render_to_string('order/invoice_order2.html', context)
# Generate PDF
html = HTML(string=html_string, base_url=settings.STATIC_URL)
# Generate PDF - use template directory as base_url so images resolve correctly
html = HTML(string=html_string, base_url=template_dir)
pdf_file = BytesIO()
html.write_pdf(pdf_file)
pdf_file.seek(0)
@@ -146,6 +156,13 @@ def generate_shop_order_invoice(shop_order_id):
# Calculate subtotal (cart total before discounts)
subtotal = shop_order.subtotal or 0
# Resolve image paths for the template (absolute file paths for WeasyPrint)
import os
template_dir = os.path.join(settings.BASE_DIR, 'templates', 'order')
logo_path = os.path.join(template_dir, 'logo2.png')
logo_pattern_path = os.path.join(template_dir, 'logo-pattern.png')
qr_code_path = os.path.join(template_dir, 'qr-code.png')
# Prepare context for the template
context = {
'shop_order': shop_order,
@@ -175,13 +192,16 @@ def generate_shop_order_invoice(shop_order_id):
'is_paid': shop_order.is_paid,
'status': shop_order.get_status_display(),
'is_settled': shop_order.is_settled,
'logo_path': logo_path,
'logo_pattern_path': logo_pattern_path,
'qr_code_path': qr_code_path,
}
# Render HTML template
html_string = render_to_string('order/invoice_shop_order.html', context)
html_string = render_to_string('order/invoice_shop_order2.html', context)
# Generate PDF
html = HTML(string=html_string, base_url=settings.STATIC_URL)
# Generate PDF - use template directory as base_url so images resolve correctly
html = HTML(string=html_string, base_url=template_dir)
pdf_file = BytesIO()
html.write_pdf(pdf_file)
pdf_file.seek(0)