mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Add validation for StockItemTestResult based on the matching PartTestTemplate
This commit is contained in:
parent
e8c402ecd9
commit
fc6cad475a
@ -39,7 +39,10 @@ class EditPartTestTemplateForm(HelperForm):
|
|||||||
fields = [
|
fields = [
|
||||||
'part',
|
'part',
|
||||||
'test_name',
|
'test_name',
|
||||||
'required'
|
'description',
|
||||||
|
'required',
|
||||||
|
'requires_value',
|
||||||
|
'requires_attachment',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -1115,6 +1115,28 @@ class StockItemTestResult(models.Model):
|
|||||||
})
|
})
|
||||||
except (StockItem.DoesNotExist, StockItemAttachment.DoesNotExist):
|
except (StockItem.DoesNotExist, StockItemAttachment.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# If this test result corresponds to a template, check the requirements of the template
|
||||||
|
key = helpers.generateTestKey(self.test)
|
||||||
|
|
||||||
|
templates = self.stock_item.part.getTestTemplates()
|
||||||
|
|
||||||
|
for template in templates:
|
||||||
|
if key == template.key:
|
||||||
|
|
||||||
|
if template.requires_value:
|
||||||
|
if not self.value:
|
||||||
|
raise ValidationError({
|
||||||
|
"value": _("Value must be provided for this test"),
|
||||||
|
})
|
||||||
|
|
||||||
|
if template.requires_attachment:
|
||||||
|
if not self.attachment:
|
||||||
|
raise ValidationError({
|
||||||
|
"attachment": _("Attachment must be uploaded for this test"),
|
||||||
|
})
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
stock_item = models.ForeignKey(
|
stock_item = models.ForeignKey(
|
||||||
StockItem,
|
StockItem,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user