diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index a276d62c54..c86027118c 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -39,7 +39,10 @@ class EditPartTestTemplateForm(HelperForm): fields = [ 'part', 'test_name', - 'required' + 'description', + 'required', + 'requires_value', + 'requires_attachment', ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index c50a58bea9..bb3621a7ac 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -1115,6 +1115,28 @@ class StockItemTestResult(models.Model): }) except (StockItem.DoesNotExist, StockItemAttachment.DoesNotExist): 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( StockItem,