diff --git a/lemarche/api/siaes/tests.py b/lemarche/api/siaes/tests.py index a7dc65ab1..6914d4235 100644 --- a/lemarche/api/siaes/tests.py +++ b/lemarche/api/siaes/tests.py @@ -360,6 +360,7 @@ def test_should_return_siae_kinds_list(self): self.assertEqual(len(response.data["results"]), 10) self.assertTrue("id" in response.data["results"][0]) self.assertTrue("name" in response.data["results"][0]) + self.assertTrue("parent" in response.data["results"][0]) def test_should_return_siae_presta_types_list(self): url = reverse("api:siae-presta-types-list") # anonymous user diff --git a/lemarche/api/siaes/views.py b/lemarche/api/siaes/views.py index 6ad2c429c..fd2b59f04 100644 --- a/lemarche/api/siaes/views.py +++ b/lemarche/api/siaes/views.py @@ -6,7 +6,7 @@ from lemarche.api.siaes.filters import SiaeFilter from lemarche.api.siaes.serializers import SiaeDetailSerializer, SiaeListSerializer -from lemarche.api.utils import BasicChoiceSerializer, check_user_token +from lemarche.api.utils import BasicChoiceSerializer, BasicChoiceWithParentSerializer, check_user_token from lemarche.siaes import constants as siae_constants from lemarche.siaes.models import Siae @@ -150,11 +150,19 @@ def _list_return(self, request, queryset, format): class SiaeKindViewSet(mixins.ListModelMixin, viewsets.GenericViewSet): - serializer_class = BasicChoiceSerializer + serializer_class = BasicChoiceWithParentSerializer queryset = Siae.objects.none() def get_queryset(self): - siae_kinds = [{"id": id, "name": name} for (id, name) in siae_constants.KIND_CHOICES] + siae_kind_insertion = [ + {"id": id, "name": name, "parent": siae_constants.KIND_PARENT_INSERTION_NAME} + for (id, name) in siae_constants.KIND_INSERTION_CHOICES + ] + siae_kind_handicap = [ + {"id": id, "name": name, "parent": siae_constants.KIND_PARENT_HANDICAP_NAME} + for (id, name) in siae_constants.KIND_HANDICAP_CHOICES + ] + siae_kinds = siae_kind_insertion + siae_kind_handicap return siae_kinds @extend_schema(summary="Lister tous les types de structures", tags=[Siae._meta.verbose_name_plural]) diff --git a/lemarche/api/utils.py b/lemarche/api/utils.py index 0a1074a4d..68d39c01e 100644 --- a/lemarche/api/utils.py +++ b/lemarche/api/utils.py @@ -39,3 +39,7 @@ def custom_preprocessing_hook(endpoints): class BasicChoiceSerializer(serializers.Serializer): id = serializers.CharField() name = serializers.CharField() + + +class BasicChoiceWithParentSerializer(BasicChoiceSerializer): + parent = serializers.CharField()