diff --git a/src/backend/InvenTree/part/models.py b/src/backend/InvenTree/part/models.py index a9109c0174..b73b36ca8e 100644 --- a/src/backend/InvenTree/part/models.py +++ b/src/backend/InvenTree/part/models.py @@ -2478,6 +2478,7 @@ class Part( category__in=categories ).order_by('-category__level') + template_ids = set() parameters = [] content_type = ContentType.objects.get_for_model(Part) @@ -2488,6 +2489,12 @@ class Part( ).exists(): continue + # Ensure we do not create duplicate parameters if multiple categories have the same template + if category_template.template.pk in template_ids: + continue + + template_ids.add(category_template.template.pk) + parameters.append( Parameter( template=category_template.template, @@ -2497,8 +2504,7 @@ class Part( ) ) - if len(parameters) > 0: - Parameter.objects.bulk_create(parameters) + Parameter.objects.bulk_create(parameters) def getTestTemplates( self, required=None, include_parent: bool = True, enabled=None