mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	@@ -17,7 +17,7 @@ from django.db.models import Sum
 | 
				
			|||||||
from django.core.validators import MinValueValidator
 | 
					from django.core.validators import MinValueValidator
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from stock.models import StockItem
 | 
					from stock.models import StockItem
 | 
				
			||||||
from part.models import BomItem
 | 
					from part.models import Part, BomItem
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Build(models.Model):
 | 
					class Build(models.Model):
 | 
				
			||||||
@@ -368,15 +368,21 @@ class BuildItem(models.Model):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        errors = {}
 | 
					        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():
 | 
					            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))]
 | 
					                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:
 | 
					            if self.quantity > self.stock_item.quantity:
 | 
				
			||||||
            errors['quantity'] = [_("Allocated quantity ({n}) must not exceed available quantity ({q})".format(
 | 
					                errors['quantity'] = [_("Allocated quantity ({n}) must not exceed available quantity ({q})".format(
 | 
				
			||||||
                n=self.quantity,
 | 
					                    n=self.quantity,
 | 
				
			||||||
                q=self.stock_item.quantity
 | 
					                    q=self.stock_item.quantity
 | 
				
			||||||
            ))]
 | 
					                ))]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        except StockItem.DoesNotExist:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        except Part.DoesNotExist:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if len(errors) > 0:
 | 
					        if len(errors) > 0:
 | 
				
			||||||
            raise ValidationError(errors)
 | 
					            raise ValidationError(errors)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -858,13 +858,19 @@ class BomItem(models.Model):
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # A part cannot refer to itself in its BOM
 | 
					        # A part cannot refer to itself in its BOM
 | 
				
			||||||
        if self.part == self.sub_part:
 | 
					        try:
 | 
				
			||||||
            raise ValidationError({'sub_part': _('Part cannot be added to its own Bill of Materials')})
 | 
					            if self.sub_part is not None and self.part is not None:
 | 
				
			||||||
 | 
					                if self.part == self.sub_part:
 | 
				
			||||||
 | 
					                    raise ValidationError({'sub_part': _('Part cannot be added to its own Bill of Materials')})
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        # Test for simple recursion
 | 
					            # Test for simple recursion
 | 
				
			||||||
        for item in self.sub_part.bom_items.all():
 | 
					            for item in self.sub_part.bom_items.all():
 | 
				
			||||||
            if self.part == item.sub_part:
 | 
					                if self.part == item.sub_part:
 | 
				
			||||||
                raise ValidationError({'sub_part': _("Part '{p1}' is  used in BOM for '{p2}' (recursive)".format(p1=str(self.part), p2=str(self.sub_part)))})
 | 
					                    raise ValidationError({'sub_part': _("Part '{p1}' is  used in BOM for '{p2}' (recursive)".format(p1=str(self.part), p2=str(self.sub_part)))})
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        except Part.DoesNotExist:
 | 
				
			||||||
 | 
					            # A blank Part will be caught elsewhere
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class Meta:
 | 
					    class Meta:
 | 
				
			||||||
        verbose_name = "BOM Item"
 | 
					        verbose_name = "BOM Item"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user