From fd39c9672641f13442c7e2f7d1af54c4f8e72daf Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 30 May 2022 23:27:35 +1000 Subject: [PATCH] Fixes for related_part functionality --- InvenTree/part/models.py | 6 ++++-- InvenTree/part/test_part.py | 17 ++--------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 29a8f8ec13..cdaeb7eb59 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2093,13 +2093,15 @@ class Part(MetadataMixin, MPTTModel): related_parts_2 = self.related_parts_2.filter(part_2__id=self.pk) + related_parts.append() + for related_part in related_parts_1: # Add to related parts list - related_parts.append((related_part, related_part.part_2)) + related_parts.append(related_part.part_2) for related_part in related_parts_2: # Add to related parts list - related_parts.append((related_part, related_part.part_1)) + related_parts.append(related_part.part_1) return related_parts diff --git a/InvenTree/part/test_part.py b/InvenTree/part/test_part.py index b3c0ec5aa8..46f1473983 100644 --- a/InvenTree/part/test_part.py +++ b/InvenTree/part/test_part.py @@ -15,8 +15,8 @@ from common.notifications import UIMessageNotification, storage from InvenTree import version from InvenTree.helpers import InvenTreeTestCase -from .models import (Part, PartCategory, PartCategoryStar, PartRelated, - PartStar, PartTestTemplate, rename_part_image) +from .models import (Part, PartCategory, PartCategoryStar, PartStar, + PartTestTemplate, rename_part_image) from .templatetags import inventree_extras @@ -160,19 +160,6 @@ class PartTest(TestCase): p = Part.objects.get(pk=100) self.assertEqual(str(p), "BOB | Bob | A2 - Can we build it?") - def test_related(self): - """Test the part relationship functionality""" - self.assertEqual(self.r1.related_count, 0) - self.assertEqual(self.r2.related_count, 0) - - PartRelated.objects.create(part_1=self.r1, part_2=self.r2) - - self.assertEqual(self.r1.related_count, 1) - self.assertEqual(self.r2.related_count, 1) - - self.assertTrue(self.r2 in self.r1.get_related_parts()) - self.assertTrue(self.r1 in self.r2.get_related_parts()) - def test_duplicate(self): """Test that we cannot create a "duplicate" Part.""" n = Part.objects.count()