mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Merge branch 'fix-boolean' of https://github.com/matmair/InvenTree into fix-boolean
This commit is contained in:
		| @@ -2,9 +2,53 @@ | ||||
| from __future__ import unicode_literals | ||||
|  | ||||
| from django.contrib import admin | ||||
| from import_export.admin import ImportExportModelAdmin | ||||
|  | ||||
| from .models import Build, BuildItem | ||||
| from import_export.admin import ImportExportModelAdmin | ||||
| from import_export.fields import Field | ||||
| from import_export.resources import ModelResource | ||||
| import import_export.widgets as widgets | ||||
|  | ||||
| from build.models import Build, BuildItem | ||||
|  | ||||
| import part.models | ||||
|  | ||||
|  | ||||
| class BuildResource(ModelResource): | ||||
|     """Class for managing import/export of Build data""" | ||||
|     # For some reason, we need to specify the fields individually for this ModelResource, | ||||
|     # but we don't for other ones. | ||||
|     # TODO: 2022-05-12 - Need to investigate why this is the case! | ||||
|  | ||||
|     pk = Field(attribute='pk') | ||||
|  | ||||
|     reference = Field(attribute='reference') | ||||
|  | ||||
|     title = Field(attribute='title') | ||||
|  | ||||
|     part = Field(attribute='part', widget=widgets.ForeignKeyWidget(part.models.Part)) | ||||
|  | ||||
|     part_name = Field(attribute='part__full_name', readonly=True) | ||||
|  | ||||
|     overdue = Field(attribute='is_overdue', readonly=True, widget=widgets.BooleanWidget()) | ||||
|  | ||||
|     completed = Field(attribute='completed', readonly=True) | ||||
|  | ||||
|     quantity = Field(attribute='quantity') | ||||
|  | ||||
|     status = Field(attribute='status') | ||||
|  | ||||
|     batch = Field(attribute='batch') | ||||
|  | ||||
|     notes = Field(attribute='notes') | ||||
|  | ||||
|     class Meta: | ||||
|         models = Build | ||||
|         skip_unchanged = True | ||||
|         report_skipped = False | ||||
|         clean_model_instances = True | ||||
|         exclude = [ | ||||
|             'lft', 'rght', 'tree_id', 'level', | ||||
|         ] | ||||
|  | ||||
|  | ||||
| class BuildAdmin(ImportExportModelAdmin): | ||||
|   | ||||
| @@ -12,13 +12,15 @@ from rest_framework import filters, generics | ||||
| from django_filters.rest_framework import DjangoFilterBackend | ||||
| from django_filters import rest_framework as rest_filters | ||||
|  | ||||
| from InvenTree.api import AttachmentMixin | ||||
| from InvenTree.helpers import str2bool, isNull | ||||
| from InvenTree.api import AttachmentMixin, APIDownloadMixin | ||||
| from InvenTree.helpers import str2bool, isNull, DownloadFile | ||||
| from InvenTree.filters import InvenTreeOrderingFilter | ||||
| from InvenTree.status_codes import BuildStatus | ||||
|  | ||||
| from .models import Build, BuildItem, BuildOrderAttachment | ||||
| import build.admin | ||||
| import build.serializers | ||||
| from build.models import Build, BuildItem, BuildOrderAttachment | ||||
|  | ||||
| from users.models import Owner | ||||
|  | ||||
|  | ||||
| @@ -71,7 +73,7 @@ class BuildFilter(rest_filters.FilterSet): | ||||
|         return queryset | ||||
|  | ||||
|  | ||||
| class BuildList(generics.ListCreateAPIView): | ||||
| class BuildList(APIDownloadMixin, generics.ListCreateAPIView): | ||||
|     """ API endpoint for accessing a list of Build objects. | ||||
|  | ||||
|     - GET: Return list of objects (with filters) | ||||
| @@ -123,6 +125,14 @@ class BuildList(generics.ListCreateAPIView): | ||||
|  | ||||
|         return queryset | ||||
|  | ||||
|     def download_queryset(self, queryset, export_format): | ||||
|         dataset = build.admin.BuildResource().export(queryset=queryset) | ||||
|  | ||||
|         filedata = dataset.export(export_format) | ||||
|         filename = f"InvenTree_BuildOrders.{export_format}" | ||||
|  | ||||
|         return DownloadFile(filedata, filename) | ||||
|  | ||||
|     def filter_queryset(self, queryset): | ||||
|  | ||||
|         queryset = super().filter_queryset(queryset) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user