diff --git a/docs/docs/settings/global.md b/docs/docs/settings/global.md index d60d02a367..817dd69a3c 100644 --- a/docs/docs/settings/global.md +++ b/docs/docs/settings/global.md @@ -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 diff --git a/src/backend/InvenTree/common/migrations/0041_auto_20251028_1112.py b/src/backend/InvenTree/common/migrations/0041_auto_20251028_1112.py index 6fe89f42ca..5407ae0b59 100644 --- a/src/backend/InvenTree/common/migrations/0041_auto_20251028_1112.py +++ b/src/backend/InvenTree/common/migrations/0041_auto_20251028_1112.py @@ -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 diff --git a/src/backend/InvenTree/common/setting/system.py b/src/backend/InvenTree/common/setting/system.py index 49d06e30b4..087e494400 100644 --- a/src/backend/InvenTree/common/setting/system.py +++ b/src/backend/InvenTree/common/setting/system.py @@ -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'), diff --git a/src/backend/InvenTree/part/models.py b/src/backend/InvenTree/part/models.py index 79c384b09a..473399e487 100644 --- a/src/backend/InvenTree/part/models.py +++ b/src/backend/InvenTree/part/models.py @@ -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: diff --git a/src/backend/InvenTree/part/test_api.py b/src/backend/InvenTree/part/test_api.py index 2344c63aa8..49c263119b 100644 --- a/src/backend/InvenTree/part/test_api.py +++ b/src/backend/InvenTree/part/test_api.py @@ -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 diff --git a/src/backend/InvenTree/part/test_param.py b/src/backend/InvenTree/part/test_param.py index 2891f5c839..acc5a00008 100644 --- a/src/backend/InvenTree/part/test_param.py +++ b/src/backend/InvenTree/part/test_param.py @@ -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 diff --git a/src/frontend/src/pages/Index/Settings/SystemSettings.tsx b/src/frontend/src/pages/Index/Settings/SystemSettings.tsx index 918033494a..0e3ef515d7 100644 --- a/src/frontend/src/pages/Index/Settings/SystemSettings.tsx +++ b/src/frontend/src/pages/Index/Settings/SystemSettings.tsx @@ -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: , + content: + }, { 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' ]} /> )