From 7e34146d17a2a5abca31675c632e0c923d5ff2b0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 13 Aug 2024 17:29:01 +0200 Subject: [PATCH] LDS-3859 : parse int value (exported file from Google Sheet contains float instead of int) --- business/mappers/excel_lines_mapper.py | 4 ++-- business/services/excel.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/business/mappers/excel_lines_mapper.py b/business/mappers/excel_lines_mapper.py index 0491202..754e477 100644 --- a/business/mappers/excel_lines_mapper.py +++ b/business/mappers/excel_lines_mapper.py @@ -37,8 +37,8 @@ def map_to_obj(self): excel_path=self.excel_path, excel_mapper=self.excel_mapper, sheet_name=parameters.sheet_name, - header_row=parameters.header_line, - min_row=parameters.content_start_line, + header_row=int(parameters.header_line), + min_row=int(parameters.content_start_line), obj_unique_key=self.unique_key, custom_dict=ConditionalDict( condition_func=self.condition, diff --git a/business/services/excel.py b/business/services/excel.py index fb9a7d3..465361f 100644 --- a/business/services/excel.py +++ b/business/services/excel.py @@ -212,7 +212,13 @@ def excel_to_dict(obj_class, excel_path, excel_mapper, sheet_name, header_row, column_indices = {col: cell.value for col, cell in enumerate(ws[header_row])} for idx, row in enumerate(ws.iter_rows(min_row=min_row, max_row=max_row, values_only=True)): obj = obj_class() - cells = {column_indices[col]: value for col, value in enumerate(row)} + + cells = { + column_indices[col]: int(value) if isinstance(value, float) and value.is_integer() else value + for col, value in enumerate(row) + if value is not None + } + for col in excel_mapper: col.set_from_excel(obj, cells.get(col.excel_column_name, None)) if obj_unique_key: