From c66f56fd10d9aa2b9ff2cb3aee208a331924b5bd Mon Sep 17 00:00:00 2001 From: juuso-j <68938778+juuso-j@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:13:33 +0300 Subject: [PATCH] Use only departments with unit organization-filter Filter with unit root_departments and departments with organization-filter. Do not auto-include department's municipalities. --- services/api.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/services/api.py b/services/api.py index 9f57361ee..26e85c944 100644 --- a/services/api.py +++ b/services/api.py @@ -864,8 +864,18 @@ def get_queryset(self): queryset = queryset.filter(muni_sq) - if "city_as_department" in filters: - val = filters["city_as_department"].lower().strip() + if "organization" in filters or "city_as_department" in filters: + val = ( + filters["organization"].lower().strip() + if "organization" in filters + else "" + ) + if len(val) == 0: + val = ( + filters["city_as_department"].lower().strip() + if "city_as_department" in filters + else "" + ) if len(val) > 0: deps_uuids = val.split(",") @@ -875,16 +885,12 @@ def get_queryset(self): uuid.UUID(deps_uuid) except ValueError: raise serializers.ValidationError( - "'city_as_department' value must be a valid UUID" + "'organization' value must be a valid UUID" ) - deps = Department.objects.filter(uuid__in=deps_uuids).select_related( - "municipality" - ) - munis = [d.municipality for d in deps] - - queryset = queryset.filter(root_department__in=deps) | queryset.filter( - municipality__in=munis + deps = Department.objects.filter(uuid__in=deps_uuids) + queryset = queryset.filter(department__in=deps) | queryset.filter( + root_department__in=deps ) if "provider_type" in filters: