2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Report template currency updates (#4469)

* Move render_currency into helpers.py

- Add duplicate tag to report.py
- Add option for currency conversion (optional)

* Update report templates

- Use "render_currency" instead of including price_data template

* Remove 'price_data.html' template entirely
This commit is contained in:
Oliver
2023-03-08 23:26:26 +11:00
committed by GitHub
parent beac7d15df
commit 34875828d7
10 changed files with 84 additions and 65 deletions

View File

@ -46,8 +46,8 @@
{% endif %}
</td>
<th>{% trans "Internal Pricing" %}</th>
<td>{% include "price_data.html" with price=pricing.internal_cost_min %}</td>
<td>{% include "price_data.html" with price=pricing.internal_cost_max %}</td>
<td>{% render_currency pricing.internal_cost_min %}</td>
<td>{% render_currency pricing.internal_cost_max %}</td>
</tr>
{% if part.purchaseable %}
<tr>
@ -59,8 +59,8 @@
{% endif %}
</td>
<th>{% trans "Purchase History" %}</th>
<td>{% include "price_data.html" with price=pricing.purchase_cost_min %}</td>
<td>{% include "price_data.html" with price=pricing.purchase_cost_max %}</td>
<td>{% render_currency pricing.purchase_cost_min %}</td>
<td>{% render_currency pricing.purchase_cost_max %}</td>
</tr>
<tr>
<td>
@ -71,8 +71,8 @@
{% endif %}
</td>
<th>{% trans "Supplier Pricing" %}</th>
<td>{% include "price_data.html" with price=pricing.supplier_price_min %}</td>
<td>{% include "price_data.html" with price=pricing.supplier_price_max %}</td>
<td>{% render_currency pricing.supplier_price_min %}</td>
<td>{% render_currency pricing.supplier_price_max %}</td>
</tr>
{% endif %}
{% if part.assembly %}
@ -85,23 +85,23 @@
{% endif %}
</td>
<th>{% trans "BOM Pricing" %}</th>
<td>{% include "price_data.html" with price=pricing.bom_cost_min %}</td>
<td>{% include "price_data.html" with price=pricing.bom_cost_max %}</td>
<td>{% render_currency pricing.bom_cost_min %}</td>
<td>{% render_currency pricing.bom_cost_max %}</td>
</tr>
{% endif %}
{% if part.is_template %}
<tr>
<td><a href='#variant-cost'><span class='fas fa-shapes'></span></a></td>
<th>{% trans "Variant Pricing" %}</th>
<td>{% include "price_data.html" with price=pricing.variant_cost_min %}</td>
<td>{% include "price_data.html" with price=pricing.variant_cost_max %}</td>
<td>{% render_currency pricing.variant_cost_min %}</td>
<td>{% render_currency pricing.variant_cost_max %}</td>
</tr>
{% endif %}
<tr>
<td></td>
<th>{% trans "Overall Pricing" %}</th>
<th>{% include "price_data.html" with price=pricing.overall_min %}</th>
<th>{% include "price_data.html" with price=pricing.overall_max %}</th>
<th>{% render_currency pricing.overall_min %}</th>
<th>{% render_currency pricing.overall_max %}</th>
</tr>
</tbody>
</table>
@ -126,8 +126,8 @@
</a>
</td>
<th>{% trans "Sale Price" %}</th>
<td>{% include "price_data.html" with price=pricing.sale_price_min %}</td>
<td>{% include "price_data.html" with price=pricing.sale_price_max %}</td>
<td>{% render_currency pricing.sale_price_min %}</td>
<td>{% render_currency pricing.sale_price_max %}</td>
</tr>
<tr>
<td>
@ -136,8 +136,8 @@
</a>
</td>
<th>{% trans "Sale History" %}</th>
<td>{% include "price_data.html" with price=pricing.sale_history_min %}</td>
<td>{% include "price_data.html" with price=pricing.sale_history_max %}</td>
<td>{% render_currency pricing.sale_history_min %}</td>
<td>{% render_currency pricing.sale_history_max %}</td>
</tr>
</tbody>
</table>

View File

@ -4,7 +4,6 @@ import logging
import os
import sys
from datetime import date, datetime
from decimal import Decimal
from django import template
from django.conf import settings as djangosettings
@ -14,8 +13,6 @@ from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
import moneyed.localization
import InvenTree.helpers
from common.models import ColorTheme, InvenTreeSetting, InvenTreeUserSetting
from common.settings import currency_code_default
@ -104,33 +101,10 @@ def render_date(context, date_object):
@register.simple_tag
def render_currency(money, decimal_places=None, include_symbol=True):
def render_currency(money, **kwargs):
"""Render a currency / Money object"""
if money is None or money.amount is None:
return '-'
if decimal_places is None:
decimal_places = InvenTreeSetting.get_setting('PRICING_DECIMAL_PLACES', 6)
value = Decimal(str(money.amount)).normalize()
value = str(value)
if '.' in value:
decimals = len(value.split('.')[-1])
decimals = max(decimals, 2)
decimals = min(decimals, decimal_places)
decimal_places = decimals
else:
decimal_places = 2
return moneyed.localization.format_money(
money,
decimal_places=decimal_places,
include_symbol=include_symbol,
)
return InvenTree.helpers.render_currency(money, **kwargs)
@register.simple_tag()