From adbb7e7682f0abcee37c42e1e9cbf68d0b2f3a0a Mon Sep 17 00:00:00 2001 From: Paulina Kujawa Date: Tue, 20 Aug 2024 16:18:38 +0200 Subject: [PATCH 1/2] fix decimal type to be float instead of string --- .../service/periodic_data_update_import_service.py | 2 +- .../tests/test_periodic_data_update_import_service.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/hct_mis_api/apps/periodic_data_update/service/periodic_data_update_import_service.py b/backend/hct_mis_api/apps/periodic_data_update/service/periodic_data_update_import_service.py index ef0811ce11..77b8c16736 100644 --- a/backend/hct_mis_api/apps/periodic_data_update/service/periodic_data_update_import_service.py +++ b/backend/hct_mis_api/apps/periodic_data_update/service/periodic_data_update_import_service.py @@ -284,7 +284,7 @@ def _get_form_field_for_value(self, flexible_attribute: FlexibleAttribute) -> fo if flexible_attribute.pdu_data.subtype == PeriodicFieldData.STRING: return forms.CharField(required=False) elif flexible_attribute.pdu_data.subtype == PeriodicFieldData.DECIMAL: - return forms.DecimalField(required=False) + return forms.FloatField(required=False) elif flexible_attribute.pdu_data.subtype == PeriodicFieldData.BOOLEAN: return StrictBooleanField(required=False) elif flexible_attribute.pdu_data.subtype == PeriodicFieldData.DATE: diff --git a/backend/hct_mis_api/apps/periodic_data_update/tests/test_periodic_data_update_import_service.py b/backend/hct_mis_api/apps/periodic_data_update/tests/test_periodic_data_update_import_service.py index 7a3ade76d1..9ef6d4cd4a 100644 --- a/backend/hct_mis_api/apps/periodic_data_update/tests/test_periodic_data_update_import_service.py +++ b/backend/hct_mis_api/apps/periodic_data_update/tests/test_periodic_data_update_import_service.py @@ -164,7 +164,7 @@ def test_import_data_decimal(self) -> None: self.assertEqual(periodic_data_update_upload.status, PeriodicDataUpdateUpload.Status.SUCCESSFUL) self.assertEqual(periodic_data_update_upload.error_message, None) self.individual.refresh_from_db() - self.assertEqual(self.individual.flex_fields[flexible_attribute.name]["1"]["value"], "20.456") + self.assertEqual(self.individual.flex_fields[flexible_attribute.name]["1"]["value"], 20.456) self.assertEqual(self.individual.flex_fields[flexible_attribute.name]["1"]["collection_date"], "2021-05-02") def test_import_data_boolean(self) -> None: From e35ca7652f00a76e1f28bf91900104dde222a3e4 Mon Sep 17 00:00:00 2001 From: Paulina Kujawa Date: Tue, 20 Aug 2024 18:50:43 +0200 Subject: [PATCH 2/2] fix in rdi import --- .../apps/registration_datahub/tasks/rdi_xlsx_create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/hct_mis_api/apps/registration_datahub/tasks/rdi_xlsx_create.py b/backend/hct_mis_api/apps/registration_datahub/tasks/rdi_xlsx_create.py index f94776a4f0..ffeb9f353e 100644 --- a/backend/hct_mis_api/apps/registration_datahub/tasks/rdi_xlsx_create.py +++ b/backend/hct_mis_api/apps/registration_datahub/tasks/rdi_xlsx_create.py @@ -534,7 +534,7 @@ def handle_pdu_fields(self, row: list[Any], header: list[Any], individual: Pendi collection_date_cell = row_dict.get(column_collection_date) subtype = flexible_attribute.pdu_data.subtype handle_subtype = handle_subtype_mapping[subtype] - value = handle_subtype(value_cell) + value = handle_subtype(value_cell, is_flex_field=True) if not collection_date_cell.value: collection_date = self.registration_data_import.created_at.date() else: