Remove global setting - simplify code

This commit is contained in:
Oliver Walters 2026-06-19 23:05:23 +00:00
parent 916120d2ce
commit f5dcffd032
7 changed files with 16 additions and 45 deletions

View File

@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- [#12208](https://github.com/inventree/InvenTree/pull/12208) adds custom locale support for rendering currencies, dates and numbers within reports. This allows users to specify a custom locale for report rendering, which can be used to control the formatting of dates, numbers and currency values in the generated reports. The custom locale can be set via the `REPORT_LOCALE` system setting, and if not set, the system will fall back to using the default system locale for report rendering.
- [#12208](https://github.com/inventree/InvenTree/pull/12208) adds custom locale support for rendering currencies, dates and numbers within reports. This allows users to specify a custom locale for report rendering, which can be used to control the formatting of dates, numbers and currency values in the generated reports.
- [#12204](https://github.com/inventree/InvenTree/pull/12204) adds new filtering options to PartCategoryTree and StockLocationTree API endpoints, allowing tree data to be fetched dynamically
- [#12165](https://github.com/inventree/InvenTree/pull/12165) adds support for parameters against the PartCategory model
- [#12103](https://github.com/inventree/InvenTree/pull/12103) adds column-based filtering to table views in the user interface. This extends the existing table filtering functionality by allowing users to apply filters directly to individual columns.

View File

@ -410,7 +410,7 @@ For rendering date and datetime information, the following helper functions are
Both functions resolve their output using the following priority order:
1. **`fmt=` argument** — a [strftime format string](https://docs.python.org/3/library/datetime.html#format-codes). When provided, this takes full priority and the `locale` argument is ignored.
2. **`locale=` argument** (or the `REPORT_LOCALE` global setting) — when no `fmt` is given, Babel formats the value in a locale-aware *medium* style (e.g. `Jan 12, 2025` for `en-us`).
2. **`locale=` argument** (or the default system locale setting) — when no `fmt` is given, Babel formats the value in a locale-aware *medium* style (e.g. `Jan 12, 2025` for `en-us`).
3. **ISO 8601 fallback** — when neither `fmt` nor a locale is available, the value is returned in ISO format (e.g. `2025-01-12`).
### format_date
@ -507,10 +507,7 @@ The locale controls how the currency symbol is rendered. Different locales produ
The locale used by `render_currency` is resolved in the following priority order:
1. **Explicit `locale=` argument** in the template tag — highest priority, always wins
2. **`REPORT_LOCALE` global setting** — applied to all reports when set, with no per-tag argument needed
3. **Server `LANGUAGE_CODE`** — the fallback when neither of the above is configured
To apply a consistent locale across all reports without modifying every template, set the `REPORT_LOCALE` global setting (via *Settings → Reporting → Report Currency Locale*). Individual templates can still override it per-tag using the `locale=` argument.
2. **Server `LANGUAGE_CODE`** — the fallback when neither of the above is configured
#### Example
@ -521,7 +518,7 @@ To apply a consistent locale across all reports without modifying every template
<em>Line Item Unit Pricing:</em>
<ul>
{% for line in order.lines %}
<!-- Locale resolved from REPORT_LOCALE setting, or server LANGUAGE_CODE -->
<!-- Locale resolved from server LANGUAGE_CODE -->
<li>{% render_currency line.price currency=order.supplier.currency %}</li>
{% endfor %}
</ul>

View File

@ -142,7 +142,6 @@ Configuration of report generation:
| Name | Description | Default | Units |
| ---- | ----------- | ------- | ----- |
{{ globalsetting("REPORT_ENABLE") }}
{{ globalsetting("REPORT_LOCALE") }}
{{ globalsetting("REPORT_DEFAULT_PAGE_SIZE") }}
{{ globalsetting("REPORT_DEBUG_MODE") }}
{{ globalsetting("REPORT_FETCH_URLS") }}

View File

@ -671,14 +671,6 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = {
'default': False,
'validator': bool,
},
'REPORT_LOCALE': {
'name': _('Default Report Locale'),
'description': _(
'Default locale to use when rendering dates, numbers, and currency values in reports (e.g. en-US, de-DE). Leave blank to use the system locale setting.'
),
'default': '',
'validator': common.validators.validate_locale,
},
'REPORT_DEBUG_MODE': {
'name': _('Debug Mode'),
'description': _('Generate reports in debug mode (HTML output)'),

View File

@ -620,24 +620,6 @@ class GlobalSettingsApiTest(InvenTreeAPITestCase):
self.assertEqual(codes, 'AUD,USD,GBP')
def test_report_currency_locale(self):
"""Test validation of the REPORT_LOCALE setting (locale string for report formatting)."""
url = reverse('api-global-setting-detail', kwargs={'key': 'REPORT_LOCALE'})
# Valid locale values are accepted
for valid in ['en-us', 'en-gb', 'en-au', 'de-de', 'fr-fr']:
response = self.patch(url, data={'value': valid}, expected_code=200)
self.assertEqual(response.data['value'], valid)
# Blank value is accepted (means "use system locale")
response = self.patch(url, data={'value': ''}, expected_code=200)
self.assertEqual(response.data['value'], '')
# Invalid locale values are rejected
for invalid in ['xx-zz', 'not-a-locale']:
response = self.patch(url, data={'value': invalid}, expected_code=400)
self.assertIn('Invalid locale value', str(response.data))
def test_company_name(self):
"""Test a settings object lifecycle e2e."""
setting = InvenTreeSetting.get_setting_object('INVENTREE_COMPANY_NAME')

View File

@ -776,23 +776,25 @@ def modulo(x: Any, y: Any, cast: Optional[type] = None) -> Any:
return cast_to_type(result, cast)
def _get_report_locale(override: Optional[str] = None) -> Optional[str]:
"""Return the locale to use for report formatting.
def _get_report_locale(override: Optional[str] = None) -> str:
"""Return the locale to use for report formatting."""
locale = override or settings.LANGUAGE_CODE
Priority: explicit override > REPORT_LOCALE global setting > None (caller falls back to LANGUAGE_CODE).
"""
if override:
return override
# Run a check to ensure that the locale is valid (i.e. can be used by babel)
try:
get_locale(locale)
except Exception:
raise ValidationError(
f'Invalid locale specified for report formatting: {locale}'
)
return get_global_setting('REPORT_LOCALE', cache=True) or settings.LANGUAGE_CODE
return locale
@register.simple_tag
def render_currency(money, **kwargs):
"""Render a currency / Money object."""
if 'locale' not in kwargs:
if locale := _get_report_locale():
kwargs['locale'] = locale
kwargs['locale'] = _get_report_locale(kwargs.get('locale'))
return InvenTree.helpers_model.render_currency(money, **kwargs)

View File

@ -197,7 +197,6 @@ export default function SystemSettings() {
<GlobalSettingList
keys={[
'REPORT_ENABLE',
'REPORT_LOCALE',
'REPORT_DEFAULT_PAGE_SIZE',
'REPORT_DEBUG_MODE',
'REPORT_FETCH_URLS',