mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 15:15:42 +00:00 
			
		
		
		
	Merge branch 'fix-boolean' of https://github.com/matmair/InvenTree into fix-boolean
This commit is contained in:
		@@ -4,8 +4,8 @@ from __future__ import unicode_literals
 | 
			
		||||
from django.contrib import admin
 | 
			
		||||
 | 
			
		||||
from import_export.admin import ImportExportModelAdmin
 | 
			
		||||
from import_export.resources import ModelResource
 | 
			
		||||
from import_export.fields import Field
 | 
			
		||||
from import_export.resources import ModelResource
 | 
			
		||||
import import_export.widgets as widgets
 | 
			
		||||
 | 
			
		||||
from company.models import SupplierPart
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,7 @@ from . import serializers as part_serializers
 | 
			
		||||
 | 
			
		||||
from InvenTree.helpers import str2bool, isNull, increment
 | 
			
		||||
from InvenTree.helpers import DownloadFile
 | 
			
		||||
from InvenTree.api import AttachmentMixin
 | 
			
		||||
from InvenTree.api import AttachmentMixin, APIDownloadMixin
 | 
			
		||||
 | 
			
		||||
from InvenTree.status_codes import BuildStatus, PurchaseOrderStatus, SalesOrderStatus
 | 
			
		||||
 | 
			
		||||
@@ -847,7 +847,7 @@ class PartFilter(rest_filters.FilterSet):
 | 
			
		||||
    virtual = rest_filters.BooleanFilter()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PartList(generics.ListCreateAPIView):
 | 
			
		||||
class PartList(APIDownloadMixin, generics.ListCreateAPIView):
 | 
			
		||||
    """
 | 
			
		||||
    API endpoint for accessing a list of Part objects
 | 
			
		||||
 | 
			
		||||
@@ -897,6 +897,14 @@ class PartList(generics.ListCreateAPIView):
 | 
			
		||||
 | 
			
		||||
        return self.serializer_class(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def download_queryset(self, queryset, export_format):
 | 
			
		||||
        dataset = PartResource().export(queryset=queryset)
 | 
			
		||||
 | 
			
		||||
        filedata = dataset.export(export_format)
 | 
			
		||||
        filename = f"InvenTree_Parts.{export_format}"
 | 
			
		||||
 | 
			
		||||
        return DownloadFile(filedata, filename)
 | 
			
		||||
 | 
			
		||||
    def list(self, request, *args, **kwargs):
 | 
			
		||||
        """
 | 
			
		||||
        Overide the 'list' method, as the PartCategory objects are
 | 
			
		||||
@@ -908,22 +916,6 @@ class PartList(generics.ListCreateAPIView):
 | 
			
		||||
 | 
			
		||||
        queryset = self.filter_queryset(self.get_queryset())
 | 
			
		||||
 | 
			
		||||
        # Check if we wish to export the queried data to a file.
 | 
			
		||||
        # If so, skip pagination!
 | 
			
		||||
        export_format = request.query_params.get('export', None)
 | 
			
		||||
 | 
			
		||||
        if export_format:
 | 
			
		||||
            export_format = str(export_format).strip().lower()
 | 
			
		||||
 | 
			
		||||
            if export_format in ['csv', 'tsv', 'xls', 'xlsx']:
 | 
			
		||||
                dataset = PartResource().export(queryset=queryset)
 | 
			
		||||
 | 
			
		||||
                filedata = dataset.export(export_format)
 | 
			
		||||
 | 
			
		||||
                filename = f"InvenTree_Parts.{export_format}"
 | 
			
		||||
 | 
			
		||||
                return DownloadFile(filedata, filename)
 | 
			
		||||
 | 
			
		||||
        page = self.paginate_queryset(queryset)
 | 
			
		||||
 | 
			
		||||
        if page is not None:
 | 
			
		||||
 
 | 
			
		||||
@@ -2233,7 +2233,7 @@ class Part(MPTTModel):
 | 
			
		||||
        for child in children:
 | 
			
		||||
            parts.append(child)
 | 
			
		||||
 | 
			
		||||
        # Immediate parent
 | 
			
		||||
        # Immediate parent, and siblings
 | 
			
		||||
        if self.variant_of:
 | 
			
		||||
            parts.append(self.variant_of)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user