mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
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:
parent
d52a839cf2
commit
9ebbc2f9f6
@ -3532,15 +3532,6 @@ class PartParameter(MetadataMixin, models.Model):
|
|||||||
|
|
||||||
super().clean()
|
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
|
# 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:
|
||||||
|
@ -168,10 +168,9 @@ class ParameterTests(TestCase):
|
|||||||
param = PartParameter(part=prt, template=template, data=value)
|
param = PartParameter(part=prt, template=template, data=value)
|
||||||
param.full_clean()
|
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']:
|
for value in ['3 Amps', '-3 zogs', '3.14F']:
|
||||||
param = PartParameter(part=prt, template=template, data=value)
|
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):
|
def test_param_unit_conversion(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user