2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

Filter build orders by responsible owner (#4383) (#4408)

* 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:
simonkuehling
2023-02-25 03:52:12 +01:00
committed by GitHub
parent c46f153449
commit f523fb44f6
5 changed files with 54 additions and 4 deletions

View File

@ -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',