mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	remove legacy function getReuiredParts
- Was very database expensive - Not being used anywhere - use get_bom_items instead
This commit is contained in:
		@@ -1628,31 +1628,6 @@ class Part(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel):
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
        self.bom_items.all().delete()
 | 
					        self.bom_items.all().delete()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getRequiredParts(self, recursive=False, parts=None):
 | 
					 | 
				
			||||||
        """Return a list of parts required to make this part (i.e. BOM items).
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Args:
 | 
					 | 
				
			||||||
            recursive: If True iterate down through sub-assemblies
 | 
					 | 
				
			||||||
            parts: Set of parts already found (to prevent recursion issues)
 | 
					 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        if parts is None:
 | 
					 | 
				
			||||||
            parts = set()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        bom_items = self.get_bom_items()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for bom_item in bom_items:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            sub_part = bom_item.sub_part
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if sub_part not in parts:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                parts.add(sub_part)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if recursive:
 | 
					 | 
				
			||||||
                    sub_part.getRequiredParts(recursive=True, parts=parts)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return parts
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def supplier_count(self):
 | 
					    def supplier_count(self):
 | 
				
			||||||
        """Return the number of supplier parts available for this part."""
 | 
					        """Return the number of supplier parts available for this part."""
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,14 +44,6 @@ class BomItemTest(TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        self.assertEqual(self.bob.bom_count, 4)
 | 
					        self.assertEqual(self.bob.bom_count, 4)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_in_bom(self):
 | 
					 | 
				
			||||||
        """Test BOM aggregation"""
 | 
					 | 
				
			||||||
        parts = self.bob.getRequiredParts()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.assertIn(self.orphan, parts)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.assertTrue(self.bob.check_if_part_in_bom(self.orphan))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_used_in(self):
 | 
					    def test_used_in(self):
 | 
				
			||||||
        """Test that the 'used_in_count' attribute is calculated correctly"""
 | 
					        """Test that the 'used_in_count' attribute is calculated correctly"""
 | 
				
			||||||
        self.assertEqual(self.bob.used_in_count, 1)
 | 
					        self.assertEqual(self.bob.used_in_count, 1)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user