Do not enforce unit type conversion for part parameters (#5160)

* Do not enforce unit type conversion for part parameters

- Still convert to "native value" (if possible)

* update unit tests
This commit is contained in:
Oliver 2023-07-04 21:57:43 +10:00 committed by GitHub
parent d52a839cf2
commit 9ebbc2f9f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 12 deletions

View File

@ -3532,15 +3532,6 @@ class PartParameter(MetadataMixin, models.Model):
super().clean()
# Validate the parameter data against the template units
if 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:

View File

@ -168,11 +168,10 @@ class ParameterTests(TestCase):
param = PartParameter(part=prt, template=template, data=value)
param.full_clean()
# Test that invalid parameters fail
# Invalid units also pass, but will be converted to the template units
for value in ['3 Amps', '-3 zogs', '3.14F']:
param = PartParameter(part=prt, template=template, data=value)
with self.assertRaises(django_exceptions.ValidationError):
param.full_clean()
param.full_clean()
def test_param_unit_conversion(self):
"""Test that parameters are correctly converted to template units"""