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

Decimal rendering - support "minimum places" setting (#4527)

* Add configurable setting for "minimum" decimal places

* Specify minimum decimal places to 'render_currency'

* Fix for rendering currency in tables
This commit is contained in:
Oliver
2023-03-24 23:46:29 +11:00
committed by GitHub
parent 4006ccfa0d
commit be92a4345c
4 changed files with 28 additions and 14 deletions

View File

@ -14,7 +14,8 @@
{% include "InvenTree/settings/setting.html" with key="INVENTREE_DEFAULT_CURRENCY" icon="fa-globe" %}
{% include "InvenTree/settings/setting.html" with key="PART_INTERNAL_PRICE" %}
{% include "InvenTree/settings/setting.html" with key="PART_BOM_USE_INTERNAL_PRICE" %}
{% include "InvenTree/settings/setting.html" with key="PRICING_DECIMAL_PLACES" %}
{% include "InvenTree/settings/setting.html" with key="PRICING_DECIMAL_PLACES_MIN" icon='fa-dollar-sign' %}
{% include "InvenTree/settings/setting.html" with key="PRICING_DECIMAL_PLACES" icon='fa-dollar-sign' %}
{% include "InvenTree/settings/setting.html" with key="PRICING_UPDATE_DAYS" icon='fa-calendar-alt' %}
<tr><td colspan='5'></td></tr>
{% include "InvenTree/settings/setting.html" with key="PRICING_USE_SUPPLIER_PRICING" icon='fa-check-circle' %}

View File

@ -45,24 +45,22 @@ function formatCurrency(value, options={}) {
return null;
}
var digits = options.digits || global_settings.PRICING_DECIMAL_PLACES || 6;
// Strip out any trailing zeros, etc
value = formatDecimal(value, digits);
let maxDigits = options.digits || global_settings.PRICING_DECIMAL_PLACES || 6;
let minDigits = options.minDigits || global_settings.PRICING_DECIMAL_PLACES_MIN || 0;
// Extract default currency information
var currency = options.currency || global_settings.INVENTREE_DEFAULT_CURRENCY || 'USD';
let currency = options.currency || global_settings.INVENTREE_DEFAULT_CURRENCY || 'USD';
// Exctract locale information
var locale = options.locale || navigator.language || 'en-US';
let locale = options.locale || navigator.language || 'en-US';
var formatter = new Intl.NumberFormat(
let formatter = new Intl.NumberFormat(
locale,
{
style: 'currency',
currency: currency,
maximumSignificantDigits: digits,
maximumFractionDigits: maxDigits,
minimumFractionDigits: minDigits,
}
);