feat: Add price formatting filter and update invoice templates for improved display
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter(name='price_format')
|
||||
def price_format(value):
|
||||
"""
|
||||
Format a number with thousand separators (commas).
|
||||
Example: 1234567 -> 1,234,567
|
||||
"""
|
||||
try:
|
||||
# Convert to int to remove decimals
|
||||
value = int(float(value))
|
||||
# Format with thousand separators
|
||||
return "{:,}".format(value)
|
||||
except (ValueError, TypeError):
|
||||
return value
|
||||
@@ -1,4 +1,4 @@
|
||||
{% load humanize %}
|
||||
{% load price_filters %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
@@ -277,22 +277,22 @@
|
||||
<td>{{ item_data.item.product.product.name }}</td>
|
||||
<td>{{ item_data.item.product.title }}</td>
|
||||
<td>{{ item_data.item.quantity }}</td>
|
||||
<td>{{ item_data.price_before_discount|floatformat:0|intcomma }} تومان</td>
|
||||
<td>{{ item_data.price_before_discount|price_format }} تومان</td>
|
||||
<td class="discount-highlight">
|
||||
{% if item_data.item.discount_percent > 0 %}
|
||||
{{ item_data.item.discount_percent }}% ({{ item_data.discount_amount|floatformat:0|intcomma }} تومان)
|
||||
{{ item_data.item.discount_percent }}% ({{ item_data.discount_amount|price_format }} تومان)
|
||||
{% else %}
|
||||
---
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="discount-highlight">
|
||||
{% if item_data.item.special_discount_amount > 0 %}
|
||||
{{ item_data.item.special_discount_amount|floatformat:0|intcomma }} تومان
|
||||
{{ item_data.item.special_discount_amount|price_format }} تومان
|
||||
{% else %}
|
||||
---
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ item_data.item.price|floatformat:0|intcomma }} تومان</td>
|
||||
<td>{{ item_data.item.price|price_format }} تومان</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -306,27 +306,27 @@
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">جمع کل:</span>
|
||||
<span class="summary-value">{{ subtotal|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value">{{ subtotal|price_format }} تومان</span>
|
||||
</div>
|
||||
{% if discount_amount > 0 %}
|
||||
<div class="summary-row">
|
||||
<span class="summary-label discount-highlight">تخفیف کد:</span>
|
||||
<span class="summary-value discount-highlight">{{ discount_amount|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value discount-highlight">{{ discount_amount|price_format }} تومان</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if special_discount_total > 0 %}
|
||||
<div class="summary-row">
|
||||
<span class="summary-label discount-highlight">تخفیف ویژه:</span>
|
||||
<span class="summary-value discount-highlight">{{ special_discount_total|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value discount-highlight">{{ special_discount_total|price_format }} تومان</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">مالیات:</span>
|
||||
<span class="summary-value">{{ tax|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value">{{ tax|price_format }} تومان</span>
|
||||
</div>
|
||||
<div class="summary-row total">
|
||||
<span class="summary-label">مبلغ قابل پرداخت:</span>
|
||||
<span class="summary-value">{{ final_price|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value">{{ final_price|price_format }} تومان</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% load humanize %}
|
||||
{% load price_filters %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
@@ -354,22 +354,22 @@
|
||||
<td>{{ item.order_item.product.product.name }}</td>
|
||||
<td>{{ item.order_item.product.title }}</td>
|
||||
<td>{{ item.quantity }}</td>
|
||||
<td>{{ item.unit_price|floatformat:0|intcomma }} تومان</td>
|
||||
<td>{{ item.unit_price|price_format }} تومان</td>
|
||||
<td class="discount-highlight">
|
||||
{% if item.discount_amount > 0 %}
|
||||
{{ item.order_item.discount_percent }}% ({{ item.discount_amount|floatformat:0|intcomma }} تومان)
|
||||
{{ item.order_item.discount_percent }}% ({{ item.discount_amount|price_format }} تومان)
|
||||
{% else %}
|
||||
---
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="discount-highlight">
|
||||
{% if item.special_discount_amount > 0 %}
|
||||
{{ item.special_discount_amount|floatformat:0|intcomma }} تومان
|
||||
{{ item.special_discount_amount|price_format }} تومان
|
||||
{% else %}
|
||||
---
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ item.total_price|floatformat:0|intcomma }} تومان</td>
|
||||
<td>{{ item.total_price|price_format }} تومان</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -384,23 +384,23 @@
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">جمع کل (Subtotal):</span>
|
||||
<span class="summary-value">{{ subtotal|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value">{{ subtotal|price_format }} تومان</span>
|
||||
</div>
|
||||
{% if discount_amount > 0 %}
|
||||
<div class="summary-row">
|
||||
<span class="summary-label discount-highlight">تخفیف معمولی:</span>
|
||||
<span class="summary-value discount-highlight">{{ discount_amount|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value discount-highlight">{{ discount_amount|price_format }} تومان</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if special_discount_amount > 0 %}
|
||||
<div class="summary-row">
|
||||
<span class="summary-label discount-highlight">تخفیف ویژه:</span>
|
||||
<span class="summary-value discount-highlight">{{ special_discount_amount|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value discount-highlight">{{ special_discount_amount|price_format }} تومان</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">مالیات:</span>
|
||||
<span class="summary-value">{{ tax_amount|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value">{{ tax_amount|price_format }} تومان</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -412,7 +412,7 @@
|
||||
</div>
|
||||
<div class="summary-row highlight">
|
||||
<span class="summary-label commission-highlight">مبلغ کمیسیون:</span>
|
||||
<span class="summary-value commission-highlight">{{ commission_amount|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value commission-highlight">{{ commission_amount|price_format }} تومان</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -420,7 +420,7 @@
|
||||
<h3>مبلغ نهایی</h3>
|
||||
<div class="summary-row payable">
|
||||
<span class="summary-label">مبلغ قابل پرداخت به فروشگاه:</span>
|
||||
<span class="summary-value">{{ payable_amount|floatformat:0|intcomma }} تومان</span>
|
||||
<span class="summary-value">{{ payable_amount|price_format }} تومان</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user