mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Enable attachments to be uploaded via the API
This commit is contained in:
		@@ -1102,21 +1102,17 @@ class StockItemTestResult(models.Model):
 | 
			
		||||
        date: Date the test result was recorded
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def save(self, *args, **kwargs):
 | 
			
		||||
 | 
			
		||||
        super().clean()
 | 
			
		||||
        super().validate_unique()
 | 
			
		||||
        super().save(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def clean(self):
 | 
			
		||||
 | 
			
		||||
        super().clean()
 | 
			
		||||
 | 
			
		||||
        # If an attachment is linked to this result, the attachment must also point to the item
 | 
			
		||||
        try:
 | 
			
		||||
            if self.attachment:
 | 
			
		||||
                if not self.attachment.stock_item == self.stock_item:
 | 
			
		||||
                    raise ValidationError({
 | 
			
		||||
                        'attachment': _("Test result attachment must be linked to the same StockItem"),
 | 
			
		||||
                    })
 | 
			
		||||
        except (StockItem.DoesNotExist, StockItemAttachment.DoesNotExist):
 | 
			
		||||
            pass
 | 
			
		||||
        
 | 
			
		||||
        # If this test result corresponds to a template, check the requirements of the template
 | 
			
		||||
         # 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()
 | 
			
		||||
@@ -1130,14 +1126,27 @@ class StockItemTestResult(models.Model):
 | 
			
		||||
                            "value": _("Value must be provided for this test"),
 | 
			
		||||
                        })
 | 
			
		||||
 | 
			
		||||
                """
 | 
			
		||||
                TODO: Re-introduce this at a later stage, it is buggy when uplaoding an attachment via the API
 | 
			
		||||
                if template.requires_attachment:
 | 
			
		||||
                    if not self.attachment:
 | 
			
		||||
                        raise ValidationError({
 | 
			
		||||
                            "attachment": _("Attachment must be uploaded for this test"),
 | 
			
		||||
                        })
 | 
			
		||||
 | 
			
		||||
                """
 | 
			
		||||
                
 | 
			
		||||
                break
 | 
			
		||||
 | 
			
		||||
        # If an attachment is linked to this result, the attachment must also point to the item
 | 
			
		||||
        try:
 | 
			
		||||
            if self.attachment:
 | 
			
		||||
                if not self.attachment.stock_item == self.stock_item:
 | 
			
		||||
                    raise ValidationError({
 | 
			
		||||
                        'attachment': _("Test result attachment must be linked to the same StockItem"),
 | 
			
		||||
                    })
 | 
			
		||||
        except (StockItem.DoesNotExist, StockItemAttachment.DoesNotExist):
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
    stock_item = models.ForeignKey(
 | 
			
		||||
        StockItem,
 | 
			
		||||
        on_delete=models.CASCADE,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user