mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-14 17:01:28 +00:00
Add ProjectCode support to build orders (#4808)
* Add "project_code" field to Build model * Add "project_code" field to Build model * build javascript updates (cherry picked from commit3e27a3b739
) * Update table filters (cherry picked from commit196c675585
) * Adds API filtering * Bump API version * Hide project code field from build form if project codes not enabled (cherry picked from commit4e210e3dfa
) * refactoring to attempt to fix circular imports * Upgrade django-test-migrations package * Fix broken import * Further fixes for unit tests * Update unit tests for migration files * Fix typo in build.js * Migration test updates - Need to specify MPTT stuff * Fix build.js * Fix migration order * Update API version
This commit is contained in:
@ -16,6 +16,7 @@ from InvenTree.helpers import str2bool, isNull, DownloadFile
|
||||
from InvenTree.status_codes import BuildStatus, BuildStatusGroups
|
||||
from InvenTree.mixins import CreateAPI, RetrieveUpdateDestroyAPI, ListCreateAPI
|
||||
|
||||
import common.models
|
||||
import build.admin
|
||||
import build.serializers
|
||||
from build.models import Build, BuildLine, BuildItem, BuildOrderAttachment
|
||||
@ -89,6 +90,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.
|
||||
@ -114,11 +130,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'
|
||||
@ -129,6 +147,7 @@ class BuildList(APIDownloadMixin, ListCreateAPI):
|
||||
'part__name',
|
||||
'part__IPN',
|
||||
'part__description',
|
||||
'project_code__code',
|
||||
'priority',
|
||||
]
|
||||
|
||||
|
Reference in New Issue
Block a user