mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Fix validation for Build model (#6038)
* Fix validation for Build model - Move checks into clean() method - Allows errors to be handled cleanly when editing from the admin interface * Fix unit test
This commit is contained in:
		| @@ -109,12 +109,6 @@ class Build(MPTTModel, InvenTree.mixins.DiffMixin, InvenTree.models.InvenTreeBar | ||||
|         self.validate_reference_field(self.reference) | ||||
|         self.reference_int = self.rebuild_reference_field(self.reference) | ||||
|  | ||||
|         # Prevent changing target part after creation | ||||
|         if self.has_field_changed('part'): | ||||
|             raise ValidationError({ | ||||
|                 'part': _('Build order part cannot be changed') | ||||
|             }) | ||||
|  | ||||
|         try: | ||||
|             super().save(*args, **kwargs) | ||||
|         except InvalidMove: | ||||
| @@ -122,6 +116,17 @@ class Build(MPTTModel, InvenTree.mixins.DiffMixin, InvenTree.models.InvenTreeBar | ||||
|                 'parent': _('Invalid choice for parent build'), | ||||
|             }) | ||||
|  | ||||
|     def clean(self): | ||||
|         """Validate the BuildOrder model""" | ||||
|  | ||||
|         super().clean() | ||||
|  | ||||
|         # Prevent changing target part after creation | ||||
|         if self.has_field_changed('part'): | ||||
|             raise ValidationError({ | ||||
|                 'part': _('Build order part cannot be changed') | ||||
|             }) | ||||
|  | ||||
|     @staticmethod | ||||
|     def filterByDate(queryset, min_date, max_date): | ||||
|         """Filter by 'minimum and maximum date range'. | ||||
|   | ||||
| @@ -491,7 +491,7 @@ class BuildTest(BuildTestBase): | ||||
|         # Should not be able to change the part after the Build is saved | ||||
|         with self.assertRaises(ValidationError): | ||||
|             bo.part = assembly_2 | ||||
|             bo.save() | ||||
|             bo.clean() | ||||
|  | ||||
|     def test_cancel(self): | ||||
|         """Test cancellation of the build""" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user