mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-02 01:51:33 +00:00
API filtering updates for build list
This commit is contained in:
@@ -14,6 +14,7 @@ from InvenTree.helpers import str2bool, isNull, DownloadFile
|
|||||||
from InvenTree.status_codes import BuildStatus
|
from InvenTree.status_codes import BuildStatus
|
||||||
from InvenTree.mixins import CreateAPI, RetrieveUpdateDestroyAPI, ListCreateAPI
|
from InvenTree.mixins import CreateAPI, RetrieveUpdateDestroyAPI, ListCreateAPI
|
||||||
|
|
||||||
|
import common.models
|
||||||
import build.admin
|
import build.admin
|
||||||
import build.serializers
|
import build.serializers
|
||||||
from build.models import Build, BuildItem, BuildOrderAttachment
|
from build.models import Build, BuildItem, BuildOrderAttachment
|
||||||
@@ -87,6 +88,21 @@ class BuildFilter(rest_filters.FilterSet):
|
|||||||
lookup_expr="iexact"
|
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):
|
class BuildList(APIDownloadMixin, ListCreateAPI):
|
||||||
"""API endpoint for accessing a list of Build objects.
|
"""API endpoint for accessing a list of Build objects.
|
||||||
@@ -112,11 +128,13 @@ class BuildList(APIDownloadMixin, ListCreateAPI):
|
|||||||
'completed',
|
'completed',
|
||||||
'issued_by',
|
'issued_by',
|
||||||
'responsible',
|
'responsible',
|
||||||
|
'project_code',
|
||||||
'priority',
|
'priority',
|
||||||
]
|
]
|
||||||
|
|
||||||
ordering_field_aliases = {
|
ordering_field_aliases = {
|
||||||
'reference': ['reference_int', 'reference'],
|
'reference': ['reference_int', 'reference'],
|
||||||
|
'project_code': ['project_code__code'],
|
||||||
}
|
}
|
||||||
|
|
||||||
ordering = '-reference'
|
ordering = '-reference'
|
||||||
@@ -127,6 +145,7 @@ class BuildList(APIDownloadMixin, ListCreateAPI):
|
|||||||
'part__name',
|
'part__name',
|
||||||
'part__IPN',
|
'part__IPN',
|
||||||
'part__description',
|
'part__description',
|
||||||
|
'project_code__code',
|
||||||
'priority',
|
'priority',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@@ -108,6 +108,7 @@ src="{% static 'img/blank_image.png' %}"
|
|||||||
<td>{% trans "Build Description" %}</td>
|
<td>{% trans "Build Description" %}</td>
|
||||||
<td>{{ build.title }}</td>
|
<td>{{ build.title }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% include "project_code_data.html" with instance=build %}
|
||||||
{% include "barcode_data.html" with instance=build %}
|
{% include "barcode_data.html" with instance=build %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user