From bc778c145170a808d8c6f5a0a8223262e2e8ab6e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 25 May 2019 22:43:47 +1000 Subject: [PATCH] Prevent a Part from both having variants and being a variant of something else --- InvenTree/part/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index d03c6030e3..df948bb1c8 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -253,6 +253,15 @@ class Part(models.Model): else: return static('/img/blank_image.png') + def clean(self): + """ Perform cleaning operations for the Part model """ + + if self.has_variants and self.variant_of is not None: + raise ValidationError({ + 'variant_of': _("Part cannot be a variant of another part if it is already a template"), + 'has_variants': _("Part cannot be a template part if it is a variant of another part") + }) + name = models.CharField(max_length=100, blank=False, help_text='Part name', validators=[validators.validate_part_name] )