mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 04:25:42 +00:00
* add assigned_to filter to Build API * extend API to filter build orders by assigned owner * rename API filter to 'responsible' * add 'Responsible' filter to build oders table * add user/group icon to owners in 'Responsible' column * remove unused python class import * bump API version number * fix handling of invalid IDs * refactor filter options as a callback function * fix JS styling
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
from django.urls import include, re_path
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from rest_framework import filters
|
||||
from rest_framework.exceptions import ValidationError
|
||||
@ -65,6 +66,20 @@ class BuildFilter(rest_filters.FilterSet):
|
||||
|
||||
return queryset
|
||||
|
||||
assigned_to = rest_filters.NumberFilter(label='responsible', method='filter_responsible')
|
||||
|
||||
def filter_responsible(self, queryset, name, value):
|
||||
"""Filter by orders which are assigned to the specified owner."""
|
||||
owners = list(Owner.objects.filter(pk=value))
|
||||
|
||||
# if we query by a user, also find all ownerships through group memberships
|
||||
if len(owners) > 0 and owners[0].label() == 'user':
|
||||
owners = Owner.get_owners_matching_user(User.objects.get(pk=owners[0].owner_id))
|
||||
|
||||
queryset = queryset.filter(responsible__in=owners)
|
||||
|
||||
return queryset
|
||||
|
||||
# Exact match for reference
|
||||
reference = rest_filters.CharFilter(
|
||||
label='Filter by exact reference',
|
||||
|
Reference in New Issue
Block a user