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>
|
<!DOCTYPE html>
|
||||||
<html lang="fa" dir="rtl">
|
<html lang="fa" dir="rtl">
|
||||||
<head>
|
<head>
|
||||||
@@ -277,22 +277,22 @@
|
|||||||
<td>{{ item_data.item.product.product.name }}</td>
|
<td>{{ item_data.item.product.product.name }}</td>
|
||||||
<td>{{ item_data.item.product.title }}</td>
|
<td>{{ item_data.item.product.title }}</td>
|
||||||
<td>{{ item_data.item.quantity }}</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">
|
<td class="discount-highlight">
|
||||||
{% if item_data.item.discount_percent > 0 %}
|
{% 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 %}
|
{% else %}
|
||||||
---
|
---
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="discount-highlight">
|
<td class="discount-highlight">
|
||||||
{% if item_data.item.special_discount_amount > 0 %}
|
{% 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 %}
|
{% else %}
|
||||||
---
|
---
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ item_data.item.price|floatformat:0|intcomma }} تومان</td>
|
<td>{{ item_data.item.price|price_format }} تومان</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -306,27 +306,27 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
<span class="summary-label">جمع کل:</span>
|
<span class="summary-label">جمع کل:</span>
|
||||||
<span class="summary-value">{{ subtotal|floatformat:0|intcomma }} تومان</span>
|
<span class="summary-value">{{ subtotal|price_format }} تومان</span>
|
||||||
</div>
|
</div>
|
||||||
{% if discount_amount > 0 %}
|
{% if discount_amount > 0 %}
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
<span class="summary-label discount-highlight">تخفیف کد:</span>
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if special_discount_total > 0 %}
|
{% if special_discount_total > 0 %}
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
<span class="summary-label discount-highlight">تخفیف ویژه:</span>
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
<span class="summary-label">مالیات:</span>
|
<span class="summary-label">مالیات:</span>
|
||||||
<span class="summary-value">{{ tax|floatformat:0|intcomma }} تومان</span>
|
<span class="summary-value">{{ tax|price_format }} تومان</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="summary-row total">
|
<div class="summary-row total">
|
||||||
<span class="summary-label">مبلغ قابل پرداخت:</span>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% load humanize %}
|
{% load price_filters %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fa" dir="rtl">
|
<html lang="fa" dir="rtl">
|
||||||
<head>
|
<head>
|
||||||
@@ -354,22 +354,22 @@
|
|||||||
<td>{{ item.order_item.product.product.name }}</td>
|
<td>{{ item.order_item.product.product.name }}</td>
|
||||||
<td>{{ item.order_item.product.title }}</td>
|
<td>{{ item.order_item.product.title }}</td>
|
||||||
<td>{{ item.quantity }}</td>
|
<td>{{ item.quantity }}</td>
|
||||||
<td>{{ item.unit_price|floatformat:0|intcomma }} تومان</td>
|
<td>{{ item.unit_price|price_format }} تومان</td>
|
||||||
<td class="discount-highlight">
|
<td class="discount-highlight">
|
||||||
{% if item.discount_amount > 0 %}
|
{% 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 %}
|
{% else %}
|
||||||
---
|
---
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="discount-highlight">
|
<td class="discount-highlight">
|
||||||
{% if item.special_discount_amount > 0 %}
|
{% if item.special_discount_amount > 0 %}
|
||||||
{{ item.special_discount_amount|floatformat:0|intcomma }} تومان
|
{{ item.special_discount_amount|price_format }} تومان
|
||||||
{% else %}
|
{% else %}
|
||||||
---
|
---
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ item.total_price|floatformat:0|intcomma }} تومان</td>
|
<td>{{ item.total_price|price_format }} تومان</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -384,23 +384,23 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
<span class="summary-label">جمع کل (Subtotal):</span>
|
<span class="summary-label">جمع کل (Subtotal):</span>
|
||||||
<span class="summary-value">{{ subtotal|floatformat:0|intcomma }} تومان</span>
|
<span class="summary-value">{{ subtotal|price_format }} تومان</span>
|
||||||
</div>
|
</div>
|
||||||
{% if discount_amount > 0 %}
|
{% if discount_amount > 0 %}
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
<span class="summary-label discount-highlight">تخفیف معمولی:</span>
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if special_discount_amount > 0 %}
|
{% if special_discount_amount > 0 %}
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
<span class="summary-label discount-highlight">تخفیف ویژه:</span>
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
<span class="summary-label">مالیات:</span>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -412,7 +412,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="summary-row highlight">
|
<div class="summary-row highlight">
|
||||||
<span class="summary-label commission-highlight">مبلغ کمیسیون:</span>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -420,7 +420,7 @@
|
|||||||
<h3>مبلغ نهایی</h3>
|
<h3>مبلغ نهایی</h3>
|
||||||
<div class="summary-row payable">
|
<div class="summary-row payable">
|
||||||
<span class="summary-label">مبلغ قابل پرداخت به فروشگاه:</span>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user