From 9e571d40bd3a86526e7185dd2fcd9e7c5f6f0ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riku=20Kestila=CC=88?= Date: Mon, 18 Sep 2023 17:59:45 +0300 Subject: [PATCH] fix: pay subsidies were not created when handler submits application --- .../api/v1/serializers/application.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/benefit/applications/api/v1/serializers/application.py b/backend/benefit/applications/api/v1/serializers/application.py index ea922f1ebf..c146957a96 100755 --- a/backend/benefit/applications/api/v1/serializers/application.py +++ b/backend/benefit/applications/api/v1/serializers/application.py @@ -1381,7 +1381,21 @@ def update(self, instance, validated_data): _("Application can not be changed in this status") ) calculation_data = validated_data.pop("calculation", None) - pay_subsidy_data = validated_data.pop("pay_subsidies", None) + # FIX for HL-639 where application submitted manually by handler is missing pay subsidies in the DB + # because in the JSON payload pay_subsidies is an empty list and thus not None + # here we check that this is the final submit request from the handler and if so, we set pay_subsidies to None + if ( + instance.application_origin == ApplicationOrigin.HANDLER + and validated_data["status"] == ApplicationStatus.RECEIVED + ): + del validated_data["pay_subsidies"] + pay_subsidy_data = None + else: + if "pay_subsidies" in validated_data: + pay_subsidy_data = validated_data["pay_subsidies"] + del validated_data["pay_subsidies"] + else: + pay_subsidy_data = None training_compensation_data = validated_data.pop("training_compensations", None) previous_status = instance.status application = self._base_update(instance, validated_data)