2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-16 17:28:11 +00:00

Check global setting for unit validation

This commit is contained in:
Oliver Walters
2025-11-24 12:22:52 +00:00
parent 2432762451
commit 173839d76b

View File

@@ -2587,6 +2587,20 @@ class Parameter(
"""Validate the Parameter before saving to the database.""" """Validate the Parameter before saving to the database."""
super().clean() super().clean()
# Validate the parameter data against the template units
if (
get_global_setting(
'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: