mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-16 01:08:12 +00:00
Update global setting
This commit is contained in:
@@ -174,7 +174,6 @@ Configuration of label printing:
|
||||
{{ globalsetting("PART_COPY_TESTS") }}
|
||||
{{ globalsetting("PART_CATEGORY_PARAMETERS") }}
|
||||
{{ globalsetting("PART_CATEGORY_DEFAULT_ICON") }}
|
||||
{{ globalsetting("PART_PARAMETER_ENFORCE_UNITS") }}
|
||||
|
||||
#### Part Parameter Templates
|
||||
|
||||
|
||||
@@ -28,6 +28,26 @@ def convert_to_numeric_value(value: str, units: str):
|
||||
return result
|
||||
|
||||
|
||||
def update_global_setting(apps, schema_editor):
|
||||
"""Update global setting key from PART_PARAMETER_ENFORCE_UNITS to PARAMETER_ENFORCE_UNITS."""
|
||||
GlobalSetting = apps.get_model("common", "InvenTreeSetting")
|
||||
|
||||
OLD_KEY = 'PART_PARAMETER_ENFORCE_UNITS'
|
||||
NEW_KEY = 'PARAMETER_ENFORCE_UNITS'
|
||||
|
||||
try:
|
||||
setting = GlobalSetting.objects.get(key=OLD_KEY)
|
||||
|
||||
if setting is not None:
|
||||
# Remove any existing new key
|
||||
GlobalSetting.objects.filter(key=NEW_KEY).delete()
|
||||
setting.key = NEW_KEY
|
||||
setting.save()
|
||||
print(f"Updated global setting key from {OLD_KEY} to {NEW_KEY}.")
|
||||
except GlobalSetting.DoesNotExist:
|
||||
print(f"Global setting {OLD_KEY} does not exist; no update needed.")
|
||||
|
||||
|
||||
def remove_existing_parameters(apps, schema_editor):
|
||||
"""Remove any existing Parameter or ParameterTemplate objects from the database."""
|
||||
|
||||
@@ -150,6 +170,10 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
update_global_setting,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
migrations.RunPython(
|
||||
remove_existing_parameters,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
|
||||
@@ -521,14 +521,6 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = {
|
||||
'default': '',
|
||||
'validator': common.validators.validate_icon,
|
||||
},
|
||||
'PART_PARAMETER_ENFORCE_UNITS': {
|
||||
'name': _('Enforce Parameter Units'),
|
||||
'description': _(
|
||||
'If units are provided, parameter values must match the specified units'
|
||||
),
|
||||
'default': True,
|
||||
'validator': bool,
|
||||
},
|
||||
'PRICING_DECIMAL_PLACES_MIN': {
|
||||
'name': _('Minimum Pricing Decimal Places'),
|
||||
'description': _(
|
||||
@@ -669,6 +661,14 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = {
|
||||
'default': 'A4',
|
||||
'choices': report.helpers.report_page_size_options,
|
||||
},
|
||||
'PARAMETER_ENFORCE_UNITS': {
|
||||
'name': _('Enforce Parameter Units'),
|
||||
'description': _(
|
||||
'If units are provided, parameter values must match the specified units'
|
||||
),
|
||||
'default': True,
|
||||
'validator': bool,
|
||||
},
|
||||
'SERIAL_NUMBER_GLOBALLY_UNIQUE': {
|
||||
'name': _('Globally Unique Serials'),
|
||||
'description': _('Serial numbers for stock items must be globally unique'),
|
||||
|
||||
@@ -3977,20 +3977,6 @@ class PartParameter(
|
||||
"""Validate the PartParameter before saving to the database."""
|
||||
super().clean()
|
||||
|
||||
# Validate the parameter data against the template units
|
||||
if (
|
||||
get_global_setting(
|
||||
'PART_PARAMETER_ENFORCE_UNITS', True, cache=False, create=False
|
||||
)
|
||||
and self.template.units
|
||||
):
|
||||
try:
|
||||
InvenTree.conversion.convert_physical_value(
|
||||
self.data, self.template.units
|
||||
)
|
||||
except ValidationError as e:
|
||||
raise ValidationError({'data': e.message})
|
||||
|
||||
# Validate the parameter data against the template choices
|
||||
if choices := self.template.get_choices():
|
||||
if self.data not in choices:
|
||||
|
||||
@@ -237,6 +237,8 @@ class PartCategoryAPITest(InvenTreeAPITestCase):
|
||||
# Add some more category templates via the API
|
||||
n = PartParameterTemplate.objects.count()
|
||||
|
||||
raise ValueError('This test must be refactored...')
|
||||
|
||||
# Ensure validation of parameter values is disabled for these checks
|
||||
InvenTreeSetting.set_setting(
|
||||
'PART_PARAMETER_ENFORCE_UNITS', False, change_user=None
|
||||
|
||||
@@ -256,6 +256,8 @@ class ParameterTests(TestCase):
|
||||
|
||||
bad_values = ['3 Amps', '-3 zogs', '3.14F']
|
||||
|
||||
raise ValueError('This test must be refactored...')
|
||||
|
||||
# Disable enforcing of part parameter units
|
||||
InvenTreeSetting.set_setting(
|
||||
'PART_PARAMETER_ENFORCE_UNITS', False, change_user=None
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
IconCurrencyDollar,
|
||||
IconFileAnalytics,
|
||||
IconFingerprint,
|
||||
IconList,
|
||||
IconPackages,
|
||||
IconPlugConnected,
|
||||
IconQrcode,
|
||||
@@ -185,6 +186,12 @@ export default function SystemSettings() {
|
||||
/>
|
||||
)
|
||||
},
|
||||
{
|
||||
name: 'parameters',
|
||||
label: t`Parameters`,
|
||||
icon: <IconList />,
|
||||
content: <GlobalSettingList keys={['PARAMETER_ENFORCE_UNITS']} />
|
||||
},
|
||||
{
|
||||
name: 'parts',
|
||||
label: t`Parts`,
|
||||
@@ -213,8 +220,7 @@ export default function SystemSettings() {
|
||||
'PART_COPY_PARAMETERS',
|
||||
'PART_COPY_TESTS',
|
||||
'PART_CATEGORY_PARAMETERS',
|
||||
'PART_CATEGORY_DEFAULT_ICON',
|
||||
'PART_PARAMETER_ENFORCE_UNITS'
|
||||
'PART_CATEGORY_DEFAULT_ICON'
|
||||
]}
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user