From ba1ba67f87677448738055431f8856832a774c5b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 14 Aug 2021 00:46:30 +1000 Subject: [PATCH] Only add company data if part is purchaseable --- InvenTree/part/api.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 141d645ec2..1573a05538 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -643,7 +643,7 @@ class PartList(generics.ListCreateAPIView): Note: Implementation copied from DRF class CreateModelMixin """ - #TODO: Unit tests for this function! + # TODO: Unit tests for this function! serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) @@ -733,9 +733,7 @@ class PartList(generics.ListCreateAPIView): stock_item.save(user=request.user) # Optionally add manufacturer / supplier data to the part - add_supplier_info = str2bool(request.data.get('add_supplier_info', False)) - - if add_supplier_info: + if part.purchaseable and str2bool(request.data.get('add_supplier_info', False)): try: manufacturer = Company.objects.get(pk=request.data.get('manufacturer', None)) @@ -780,7 +778,7 @@ class PartList(generics.ListCreateAPIView): 'SKU': [_("This field is required")] }) - supplier_part = SupplierPart.objects.create( + SupplierPart.objects.create( part=part, supplier=supplier, SKU=sku,