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