From 279d5a00cedd84eedc37746df0e48095376e9eb4 Mon Sep 17 00:00:00 2001 From: eeintech Date: Tue, 3 Nov 2020 16:58:53 -0500 Subject: [PATCH] Switched to get_ancestors to transverse all parents categories (not only root) --- InvenTree/part/views.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 857cf94106..25d2eb8bfb 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -714,20 +714,21 @@ class PartCreate(AjaxCreateView): # Create part parameters for parent category category_templates = form.cleaned_data['parent_category_templates'] if category_templates: - # Get parent category - category = form.cleaned_data['category'].get_root() + # Get parent categories + parent_categories = form.cleaned_data['category'].get_ancestors() - for template in category.get_parameter_templates(): - # Check that template wasn't already added - if template.parameter_template not in template_list: - try: - PartParameter.create(part=part, - template=template.parameter_template, - data=template.default_value, - save=True) - except IntegrityError: - # PartParameter already exists - pass + for category in parent_categories: + for template in category.get_parameter_templates(): + # Check that template wasn't already added + if template.parameter_template not in template_list: + try: + PartParameter.create(part=part, + template=template.parameter_template, + data=template.default_value, + save=True) + except IntegrityError: + # PartParameter already exists + pass return self.renderJsonResponse(request, form, data, context=context)