mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 05:25:42 +00:00
[PUI] Category params (#6767)
* Validate default value field for PartCategoryParameterTemplate - Only if unit checks are enforced - Only if default value is not blank * Add basic table for part category parameter templates * Add functions to create / edit / delete via table * Fix unit testing
This commit is contained in:
@ -3833,6 +3833,28 @@ class PartCategoryParameterTemplate(InvenTree.models.InvenTreeMetadataModel):
|
||||
return f'{self.category.name} | {self.parameter_template.name} | {self.default_value}'
|
||||
return f'{self.category.name} | {self.parameter_template.name}'
|
||||
|
||||
def clean(self):
|
||||
"""Validate this PartCategoryParameterTemplate instance.
|
||||
|
||||
Checks the provided 'default_value', and (if not blank), ensure it is valid.
|
||||
"""
|
||||
super().clean()
|
||||
|
||||
self.default_value = (
|
||||
'' if self.default_value is None else str(self.default_value.strip())
|
||||
)
|
||||
|
||||
if self.default_value and InvenTreeSetting.get_setting(
|
||||
'PART_PARAMETER_ENFORCE_UNITS', True, cache=False, create=False
|
||||
):
|
||||
if self.parameter_template.units:
|
||||
try:
|
||||
InvenTree.conversion.convert_physical_value(
|
||||
self.default_value, self.parameter_template.units
|
||||
)
|
||||
except ValidationError as e:
|
||||
raise ValidationError({'default_value': e.message})
|
||||
|
||||
category = models.ForeignKey(
|
||||
PartCategory,
|
||||
on_delete=models.CASCADE,
|
||||
|
@ -196,6 +196,11 @@ class PartCategoryAPITest(InvenTreeAPITestCase):
|
||||
# Add some more category templates via the API
|
||||
n = PartParameterTemplate.objects.count()
|
||||
|
||||
# Ensure validation of parameter values is disabled for these checks
|
||||
InvenTreeSetting.set_setting(
|
||||
'PART_PARAMETER_ENFORCE_UNITS', False, change_user=None
|
||||
)
|
||||
|
||||
for template in PartParameterTemplate.objects.all():
|
||||
response = self.post(
|
||||
url,
|
||||
|
Reference in New Issue
Block a user