Fixes for related_part functionality

This commit is contained in:
Oliver Walters 2022-05-30 23:27:35 +10:00
parent 61491b7fe6
commit fd39c96726
2 changed files with 6 additions and 17 deletions

View File

@ -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

View File

@ -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()