mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-03 22:08:49 +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:
parent
f70a049102
commit
2aef05c1c3
@ -109,12 +109,6 @@ class Build(MPTTModel, InvenTree.mixins.DiffMixin, InvenTree.models.InvenTreeBar
|
|||||||
self.validate_reference_field(self.reference)
|
self.validate_reference_field(self.reference)
|
||||||
self.reference_int = self.rebuild_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:
|
try:
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
except InvalidMove:
|
except InvalidMove:
|
||||||
@ -122,6 +116,17 @@ class Build(MPTTModel, InvenTree.mixins.DiffMixin, InvenTree.models.InvenTreeBar
|
|||||||
'parent': _('Invalid choice for parent build'),
|
'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
|
@staticmethod
|
||||||
def filterByDate(queryset, min_date, max_date):
|
def filterByDate(queryset, min_date, max_date):
|
||||||
"""Filter by 'minimum and maximum date range'.
|
"""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
|
# Should not be able to change the part after the Build is saved
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
bo.part = assembly_2
|
bo.part = assembly_2
|
||||||
bo.save()
|
bo.clean()
|
||||||
|
|
||||||
def test_cancel(self):
|
def test_cancel(self):
|
||||||
"""Test cancellation of the build"""
|
"""Test cancellation of the build"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user