From 8edd2ab462e5d26e82ed8831c1fe32e469635ef9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 13 May 2023 22:21:38 +1000 Subject: [PATCH] API filtering updates for build list --- InvenTree/build/api.py | 19 +++++++++++++++++++ .../build/templates/build/build_base.html | 1 + 2 files changed, 20 insertions(+) diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py index a76b51fd15..8365f829bf 100644 --- a/InvenTree/build/api.py +++ b/InvenTree/build/api.py @@ -14,6 +14,7 @@ from InvenTree.helpers import str2bool, isNull, DownloadFile from InvenTree.status_codes import BuildStatus from InvenTree.mixins import CreateAPI, RetrieveUpdateDestroyAPI, ListCreateAPI +import common.models import build.admin import build.serializers from build.models import Build, BuildItem, BuildOrderAttachment @@ -87,6 +88,21 @@ class BuildFilter(rest_filters.FilterSet): lookup_expr="iexact" ) + project_code = rest_filters.ModelChoiceFilter( + queryset=common.models.ProjectCode.objects.all(), + field_name='project_code' + ) + + has_project_code = rest_filters.BooleanFilter(label='has_project_code', method='filter_has_project_code') + + def filter_has_project_code(self, queryset, name, value): + """Filter by whether or not the order has a project code""" + + if str2bool(value): + return queryset.exclude(project_code=None) + else: + return queryset.filter(project_code=None) + class BuildList(APIDownloadMixin, ListCreateAPI): """API endpoint for accessing a list of Build objects. @@ -112,11 +128,13 @@ class BuildList(APIDownloadMixin, ListCreateAPI): 'completed', 'issued_by', 'responsible', + 'project_code', 'priority', ] ordering_field_aliases = { 'reference': ['reference_int', 'reference'], + 'project_code': ['project_code__code'], } ordering = '-reference' @@ -127,6 +145,7 @@ class BuildList(APIDownloadMixin, ListCreateAPI): 'part__name', 'part__IPN', 'part__description', + 'project_code__code', 'priority', ] diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index f811d30474..614d6b4e37 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -108,6 +108,7 @@ src="{% static 'img/blank_image.png' %}" {% trans "Build Description" %} {{ build.title }} + {% include "project_code_data.html" with instance=build %} {% include "barcode_data.html" with instance=build %}