diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 31bedc5c56..38e26468f4 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -5,6 +5,7 @@ from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy from django.views.generic import DetailView, ListView +from django.forms.models import model_to_dict from company.models import Company from .models import PartCategory, Part, BomItem @@ -77,7 +78,18 @@ class PartCreate(AjaxCreateView): # Pre-fill the category field if a valid category is provided def get_initial(self): - initials = super(PartCreate, self).get_initial().copy() + # Is the client attempting to copy an existing part? + part_to_copy = self.request.GET.get('copy_part', None) + + if part_to_copy: + try: + original = Part.objects.get(pk=part_to_copy) + initials = model_to_dict(original) + except Part.DoesNotExist: + initials = super(PartCreate, self).get_initial() + + else: + initials = super(PartCreate, self).get_initial() if self.get_category_id(): initials['category'] = get_object_or_404(PartCategory, pk=self.get_category_id())