diff --git a/InvenTree/part/fixtures/part.yaml b/InvenTree/part/fixtures/part.yaml index e018c52c3b..035049fe81 100644 --- a/InvenTree/part/fixtures/part.yaml +++ b/InvenTree/part/fixtures/part.yaml @@ -97,4 +97,61 @@ tree_id: 0 level: 0 lft: 0 - rght: 0 \ No newline at end of file + rght: 0 + +# A 'template' part +- model: part.part + pk: 10000 + fields: + name: 'Chair Template' + description: 'A chair' + is_template: True + category: 7 + tree_id: 1 + level: 0 + lft: 0 + rght: 0 + +- model: part.part + pk: 10001 + fields: + name: 'Blue Chair' + variant_of: 10000 + category: 7 + tree_id: 1 + level: 0 + lft: 0 + rght: 0 + +- model: part.part + pk: 10002 + fields: + name: 'Red chair' + variant_of: 10000 + category: 7 + tree_id: 1 + level: 0 + lft: 0 + rght: 0 + +- model: part.part + pk: 10003 + fields: + name: 'Green chair' + variant_of: 10000 + category: 7 + tree_id: 1 + level: 0 + lft: 0 + rght: 0 + +- model: part.part + pk: 10004 + fields: + name: 'Green chair variant' + variant_of: 10003 + category: + tree_id: 1 + level: 0 + lft: 0 + rght: 0 diff --git a/InvenTree/part/test_part.py b/InvenTree/part/test_part.py index c7c3c014a1..0ecb9b5997 100644 --- a/InvenTree/part/test_part.py +++ b/InvenTree/part/test_part.py @@ -52,6 +52,18 @@ class PartTest(TestCase): self.C1 = Part.objects.get(name='C_22N_0805') + Part.objects.rebuild() + + def test_tree(self): + # Test that the part variant tree is working properly + chair = Part.objects.get(pk=10000) + self.assertEqual(chair.get_children().count(), 3) + self.assertEqual(chair.get_descendant_count(), 4) + + green = Part.objects.get(pk=10004) + self.assertEqual(green.get_ancestors().count(), 2) + self.assertEqual(green.get_root(), chair) + def test_str(self): p = Part.objects.get(pk=100) self.assertEqual(str(p), "BOB | Bob | A2 - Can we build it?")