From 2760efac18c923b92497c55a7342f44bb7e5cdbd Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 25 May 2019 22:01:30 +1000 Subject: [PATCH] Fix similar error for Build object --- InvenTree/build/models.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 92f04bdcc6..763686b765 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -368,15 +368,21 @@ class BuildItem(models.Model): errors = {} - if self.stock_item is not None and self.stock_item.part is not None: + try: if self.stock_item.part not in self.build.part.required_parts(): errors['stock_item'] = [_("Selected stock item not found in BOM for part '{p}'".format(p=self.build.part.full_name))] - if self.stock_item is not None and self.quantity > self.stock_item.quantity: - errors['quantity'] = [_("Allocated quantity ({n}) must not exceed available quantity ({q})".format( - n=self.quantity, - q=self.stock_item.quantity - ))] + if self.quantity > self.stock_item.quantity: + errors['quantity'] = [_("Allocated quantity ({n}) must not exceed available quantity ({q})".format( + n=self.quantity, + q=self.stock_item.quantity + ))] + + except StockItem.DoesNotExist: + pass + + except Part.DoesNotExist: + pass if len(errors) > 0: raise ValidationError(errors)