mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adjust "render_currency" behaviour (#8017)
* Adjust "render_currency" behaviour - Fixes https://github.com/inventree/InvenTree/issues/7997 * Update docs
This commit is contained in:
parent
99e822213d
commit
9afc6cc6cb
@ -130,8 +130,8 @@ The following keyword arguments are available to the `render_currency` function:
|
|||||||
| --- | --- |
|
| --- | --- |
|
||||||
| currency | Specify the currency code to render in (will attempt conversion if different to provided currency) |
|
| currency | Specify the currency code to render in (will attempt conversion if different to provided currency) |
|
||||||
| decimal_places | Specify the number of decimal places to render |
|
| decimal_places | Specify the number of decimal places to render |
|
||||||
| min_decimal_places | Specify the minimum number of decimal places to render (ignored if *decimal_places* is specified) |
|
| min_decimal_places | Specify the minimum number of decimal places to render |
|
||||||
| max_decimal_places | Specify the maximum number of decimal places to render (ignored if *decimal_places* is specified) |
|
| max_decimal_places | Specify the maximum number of decimal places to render |
|
||||||
| include_symbol | Include currency symbol in rendered value (default = True) |
|
| include_symbol | Include currency symbol in rendered value (default = True) |
|
||||||
|
|
||||||
## Maths Operations
|
## Maths Operations
|
||||||
|
@ -210,9 +210,6 @@ def render_currency(
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if decimal_places is None:
|
|
||||||
decimal_places = get_global_setting('PRICING_DECIMAL_PLACES', 6)
|
|
||||||
|
|
||||||
if min_decimal_places is None:
|
if min_decimal_places is None:
|
||||||
min_decimal_places = get_global_setting('PRICING_DECIMAL_PLACES_MIN', 0)
|
min_decimal_places = get_global_setting('PRICING_DECIMAL_PLACES_MIN', 0)
|
||||||
|
|
||||||
@ -222,17 +219,19 @@ def render_currency(
|
|||||||
value = Decimal(str(money.amount)).normalize()
|
value = Decimal(str(money.amount)).normalize()
|
||||||
value = str(value)
|
value = str(value)
|
||||||
|
|
||||||
if '.' in value:
|
if decimal_places is not None:
|
||||||
decimals = len(value.split('.')[-1])
|
# Decimal place count is provided, use it
|
||||||
|
pass
|
||||||
decimals = max(decimals, min_decimal_places)
|
elif '.' in value:
|
||||||
decimals = min(decimals, decimal_places)
|
# If the value has a decimal point, use the number of decimal places in the value
|
||||||
|
decimal_places = len(value.split('.')[-1])
|
||||||
decimal_places = decimals
|
|
||||||
else:
|
else:
|
||||||
decimal_places = max(decimal_places, 2)
|
# No decimal point, use 2 as a default
|
||||||
|
decimal_places = 2
|
||||||
|
|
||||||
decimal_places = max(decimal_places, max_decimal_places)
|
# Clip the decimal places to the specified range
|
||||||
|
decimal_places = max(decimal_places, min_decimal_places)
|
||||||
|
decimal_places = min(decimal_places, max_decimal_places)
|
||||||
|
|
||||||
return format_money(
|
return format_money(
|
||||||
money, decimal_places=decimal_places, include_symbol=include_symbol
|
money, decimal_places=decimal_places, include_symbol=include_symbol
|
||||||
|
Loading…
Reference in New Issue
Block a user