From 0677cec709a5d68e66b4e58c6cb874707fee0e8b Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 16 Feb 2022 09:44:56 +0100 Subject: [PATCH] #118 API ActionTypes * adds support for multiple action_type entries on one CompensationAction --- api/utils/serializer/v1/serializer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api/utils/serializer/v1/serializer.py b/api/utils/serializer/v1/serializer.py index f56db81..caae2de 100644 --- a/api/utils/serializer/v1/serializer.py +++ b/api/utils/serializer/v1/serializer.py @@ -367,7 +367,9 @@ class AbstractCompensationAPISerializerV1Mixin: """ actions = [] for entry in actions_data: - action = entry["action"] + action_types = [ + self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_ID) for e in entry["action_types"] + ] action_details = [ self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_DETAIL_ID) for e in entry["action_details"] ] @@ -384,7 +386,7 @@ class AbstractCompensationAPISerializerV1Mixin: # If this exact data is already existing, we do not create it new. Instead put it's id in the list of # entries, we will use to set the new actions action_entry = obj.actions.filter( - action_type__atom_id=action, + action_type__in=action_types, amount=amount, unit=unit, comment=comment, @@ -396,13 +398,13 @@ class AbstractCompensationAPISerializerV1Mixin: else: # Create and add id to list action_entry = CompensationAction.objects.create( - action_type=self._konova_code_from_json(action, CODELIST_COMPENSATION_ACTION_ID), amount=amount, unit=unit, comment=comment, ) actions.append(action_entry.id) + action_entry.action_type.set(action_types) action_entry.action_type_details.set(action_details) obj.actions.set(actions) return obj @@ -438,7 +440,9 @@ class AbstractCompensationAPISerializerV1Mixin: """ return [ { - "action": self._konova_code_to_json(entry.action_type), + "action_types": [ + self._konova_code_to_json(action) for action in entry.action_type.all() + ], "action_details": [ self._konova_code_to_json(detail) for detail in entry.action_type_details.all() ],