Add new global setting to control currency locale in reports
This commit is contained in:
parent
47a5064609
commit
0b4144a620
|
|
@ -142,6 +142,7 @@ Configuration of report generation:
|
|||
| Name | Description | Default | Units |
|
||||
| ---- | ----------- | ------- | ----- |
|
||||
{{ globalsetting("REPORT_ENABLE") }}
|
||||
{{ globalsetting("REPORT_CURRENCY_LOCALE") }}
|
||||
{{ globalsetting("REPORT_DEFAULT_PAGE_SIZE") }}
|
||||
{{ globalsetting("REPORT_DEBUG_MODE") }}
|
||||
{{ globalsetting("REPORT_FETCH_URLS") }}
|
||||
|
|
|
|||
|
|
@ -671,6 +671,14 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = {
|
|||
'default': False,
|
||||
'validator': bool,
|
||||
},
|
||||
'REPORT_CURRENCY_LOCALE': {
|
||||
'name': _('Report Currency Locale'),
|
||||
'description': _(
|
||||
'Locale to use when rendering currency values in reports (e.g. en-US, fr-FR). 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)'),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import re
|
|||
|
||||
from django.core.exceptions import SuspiciousFileOperation, ValidationError
|
||||
from django.core.files.storage import default_storage
|
||||
from django.utils import translation
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
import common.icons
|
||||
|
|
@ -171,3 +172,17 @@ def validate_variable_string(value: str):
|
|||
"""The passed value must be a valid variable identifier string."""
|
||||
if not re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', value):
|
||||
raise ValidationError(_('Value must be a valid variable identifier'))
|
||||
|
||||
|
||||
def validate_locale(value: str):
|
||||
"""Validate that the provided value is a valid locale string."""
|
||||
from babel import Locale
|
||||
from babel.core import UnknownLocaleError
|
||||
|
||||
if not value:
|
||||
return
|
||||
|
||||
try:
|
||||
Locale.parse(translation.to_locale(value))
|
||||
except (UnknownLocaleError, ValueError) as e:
|
||||
raise ValidationError(f"Invalid locale value: '{value}' - {e}")
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@ export default function SystemSettings() {
|
|||
<GlobalSettingList
|
||||
keys={[
|
||||
'REPORT_ENABLE',
|
||||
'REPORT_CURRENCY_LOCALE',
|
||||
'REPORT_DEFAULT_PAGE_SIZE',
|
||||
'REPORT_DEBUG_MODE',
|
||||
'REPORT_FETCH_URLS',
|
||||
|
|
|
|||
Loading…
Reference in New Issue